Q:

angular promise queue and showing loading data

I am using angular's $q promise like this:
$scope.loadingData = true; // show loading spinner in view 
var thingsToProcess = [....];

for(int i = 0; i < thingsToProcess.length; i++) {
    var itemToProcess = thingsToProcess[i];

    makeServiceCallThatReturnsPromise(itemToProcess)
        .then(function(response) {
                   processAndDisplayResponse(response);
         });
}

$loadingData = false; // hide loading spinner

Since the service call promises get queued, the loading indicator goes away before all the data is returned from the service. 
How can I keep the loading flag set till all the promises are served?

A:

you can use $q.all() here,
var promises=[];
for(int i=0; i<thingsToProcess.length; i++) {
    var itemToProcess = thingsToProcess[i];

  promises.push(  makeServiceCallThatReturnsPromise(itemToProcess)
        .then(function(response) {
                 //do some work here ?
         }));

}

$q.all(promises).then(function(){
  processAndDisplayResponse(response);
})

