$q.when() is the 2nd thing to know in promise world
The 1st thing to know is how to deal with angular's promises.
And the second is you can mix sync/async javascript libs :
var results = {};
$q.when('hello world').then(function(resolved) {
results.hello = resolved;
}));
So chaining or combine $q.all()
is easy :
function sum (a, b) {
return a + b;
}
$q.when(sum(1, 2)).then(function(resolved) {
return $anotherPromiseFunction(resolved);
})).then(function(resolved) {
alert(resolved);
}));
//or shortly
$q.when(sum(1, 2)).then($anotherPromiseFunction).then(function(resolved) {
alert(resolved);
}));
cf. [api on angularjs doc][1]
Written by David Epely
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Angularjs
Authors
Related Tags
#angularjs
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#