I would like to chain resource in AngularJS.
The goal is that resource B wait the end of ressource A before the launch.
I tried this:
var p = $q.when(true);
p = p.then(function() {
return $resource(...).query().$promise;
});
p = p.then(function() {
return $resource(...).query().$promise;
});
p = p.then(function() {
return $resource(...).query().$promise;
});
The point is that the call is not synchronous.
There is a way to group many asynchronous calls using $q.all. The docs for this are here.
$q.all() will allow you to send in all your queries and then wait for them all the return before resolving a combined promise. However, if you want your queries to happen in a specific order, this may not work.
Hope this helps.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With