My approach with Angular's $q
promise looks like this:
$scope.loadingData = true; // display loading spinner on the view
var itemsToProcess = [....];
for(int i = 0; i < itemsToProcess.length; i++) {
var itemToProcess = itemsToProcess[i];
makeServiceCallThatReturnsPromise(itemToProcess)
.then(function(response) {
processAndDisplayResponse(response);
});
}
$loadingData = false; // hide loading spinner
One issue I am facing is that since the service call promises are queued, the loading indicator disappears before all the data is returned.
How can I ensure that the loading flag remains set until all promises are fulfilled?