angularjs - Asynchronous call defer and promise chain -
i stuck ashync call chain. tried google couldn't found exact answer.
requirement have method
callapi(){ calling 4 service asynchronous. want chain asynchronous calls can defer.resolve when request done }
any great help. in advance.
you can use $q.all()
. takes array of promises , returns promise, resolve when promises in array have resolved.
example:
function callmultipleservices() { return $q.all([ //just random functions returning promises... someasyncservice(), $http.get('http://google.de'), someotherasyncservice() ]) //.then(function(resultarray) { return dosomethingwith(resultarray) }) }
the returned promise resolve array, containing resolved values of promises passed in. if want promise return single value somehow derived service results, add .then
takes results , somehow calculates final promise result (as in comment above)
Comments
Post a Comment