With a large AngularJS application, and even smaller ones, you can run into this issue where you end up with multiple identical API calls being made if your using the $q service. This occurs because there is a conflict with overlapping calls, which basically re-try the last API call for all of the call conflicts.
This happens when you aren’t bundling all of the calls up with the $q.all() function. This function receives an array of $http service objects that will resolve to an array once they’re all returned from the server.
You need to pass into the $q.all() function http promise objects which can be retrieved from the $http service.
For example:
1 2 3 4 5 6 7 8 9 10 |
var req = { method: 'POST', url: 'http://example.com', headers: { 'Content-Type': undefined }, data: { test: 'test' } } $http(req).then(function(){...}, function(){...}); |
Eliminating the .then after the $http and doing just return $http(req); will get you the promise to add to the array which you’ll pass to $q.all().