Usually I would do
$http({
method:'GET',
url: 'exmapleURL',
params: {someParams}
}).then(function(response) {
console.log(response); // response contains data I need
});
Now I have multiple such calls to run and I would like to wait for all of them to finish before doing something with their responses, and $q.all() seems to be a good place to start.
Per the AngularJS $q Service API Reference - $q.all document,
all(promises)
Combines multiple promises into a single promise that is resolved when all of the input promises are resolved.
Returns: Returns a single promise that will be resolved with an array/hash of values, each value corresponding to the promise at the same index/key in the promises array/hash. If any of the promises is resolved with a rejection, this resulting promise will be rejected with the same rejection value.
Does this mean that if I pass in an array of requests(like $q.all(calls).then(response)), the returned promises are in an array in the same order as the calls are passed in? Can I do something like response[0]
to retrieve the response data returned by the 0th call? Thank you.