All calls to $http in Angular return a promise.
The $q does not have all the bells and sounds of the Q library on which it is based, but if you look at docs , it has an all method that can be used to provide you with the necessary functionality.
Here you can use it:
app.controller('HttpController', function($http, $q) { // A hypothetical submit function $scope.submit = function() { // Set a loading variable for use in the view (to show the spinner) $scope.loading = true; var call1 = $http.get(/* ... */); var call2 = $http.get(/* ... */); var call3 = $http.get(/* ... */); $q.all([call1, call2, call3]).then(function(responses) { // responses will be an array of values the individual // promises were resolved to. For this case, we don't // need it, since we only care that they all resolved // successfully. $scope.loading = false; }, function(errorValue) { // If any of the promises is rejected, the error callback // will be resolved with that rejection value, kind of like // an early exit. We want to mark the loading variable // as false here too, and do something with the error. $scope.loading = false; }); }; });
source share