Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Chaining resource in angularjs

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.

like image 919
Julio Avatar asked Feb 13 '26 20:02

Julio


1 Answers

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.

like image 70
Davin Tryon Avatar answered Feb 15 '26 08:02

Davin Tryon



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!