how to use a for loop inside $q.all in angularjs
<p>I am trying to repeat the loop ,make a call and hold all promises.Here is my code:</p>

<pre><code>loadpages:function(id,pages){
 var msg =[];
 var finalList =[];
 $q.all([
    for(var i=1;i&lt;=pages;i++)
        this.getPages(id,i).then(function(promise){
            msg[i]= promise.data;
        })
    }),
  ]).then(function() {
    for(var j=1;j&lt;=pageNo;j++){
        finalList.push(msg[j]);
    }
  })

  getPages:function(id,pageNo){
 data.payload = {
                id: id,
                page: pageNo,               
            };
            var promise = $http.post( url,data); 
            return promise;
        },
}
</code></pre>

<p>I am getting an error when I keep a for loop inside  $q.all. How to get all list ,hold all promises and make a finallist?</p>