Which is equivalent to jQuery.when () in angular

In jQuery we can do $.when( $.ajax( "/page1.php" ), $.ajax( "/page2.php" ) ).done(function( a1, a2 ) { ... }); What is equivalent in angular? I really need to wait for all ahax calls to finish, and then do something. Thank.

+4
source share
2 answers

You can use $q.allto handle multiple promises. Also, use $ http to make calls, more angular.

Here is a good tutorial:

https://egghead.io/lessons/angularjs-q-all

Hope this helps.

+3
source

Equivalent:

$q.all([$http.get('/page1.php'),$http.get('/page2.php')]).then(function(values){
   var a1 = values[0];
   var a2 = values[1];
   ... 
});

AngularJS documentation for $ q

+2
source

All Articles