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

Popular posts from this blog

javascript - Laravel datatable invalid JSON response -

java - Exception in thread "main" org.springframework.context.ApplicationContextException: Unable to start embedded container; -

sql server 2008 - My Sql Code Get An Error Of Msg 245, Level 16, State 1, Line 1 Conversion failed when converting the varchar value '8:45 AM' to data type int -