use a local variable inside the loop to cache the value of i when the call 
is issued

the [i] in your then() is not evaluated until the response returns, at 
which point it's at 3 because all are sent and the loop is done by the time 
you get anything back





On Friday, November 28, 2014 6:20:55 AM UTC-5, lucian enache wrote:
>
> So I still haven't found a way to achieve a chained call with an arbitrary 
> number of endpoints, and therefore keep track
> of the order.
>
> any insights ?
>
> On Friday, November 28, 2014 12:45:13 AM UTC+1, lucian enache wrote:
>>
>> Hello everyone,
>>
>>
>> I have an array of addresses that I call with $http from my controller:
>>
>> vm.checkStatus = function() {
>> for(var i=0; i < vm.serverList.length; i++){ 
>> monitorService.getStatus( vm.serverList[i]).then(function(response){
>> vm.serverList[i].receivedStatus = response;
>> });
>> }
>> }
>>
>> and the Service:
>>
>> function getStatus(config) {
>> return $http(config).
>> success(function(data, status, headers, config) {
>>          console.log("status for",config.url,status);
>>          return status;
>>     }).
>> error(function(data, status, headers, config) {
>>          console.log("status for",config.url,status);
>>          return status;
>>     });
>>
>> My problem is around the order of resolving promises, for example if my 
>> serverList has a length of 3 items, the first resolved response is assigned 
>> like this : vm.serverList[2].receivedStatus = response;
>>
>> How can I keep track of the calls and assign the right response to the 
>> right item inside the serverList array ?
>>
>> Thanks
>>
>

-- 
You received this message because you are subscribed to the Google Groups 
"AngularJS" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/angular.
For more options, visit https://groups.google.com/d/optout.

Reply via email to