Passing variable to promise in a loop

后端 未结 5 1176
一生所求
一生所求 2021-01-30 05:40

I have a promise in a loop, and I don\'t know how to pass some scope variables into the promise handler.

for(var i in superarray){
    MyService.get(superarray[i         


        
5条回答
  •  抹茶落季
    2021-01-30 06:00

    Try this solution, I've used $q.all and I've added my parameter in array. It worked

       for(var i in superarray){
          $q.all([MyService.get(superarray[i].externalID), i]).then(function(results){
            var r = results[0];
            var i = results[1];
            console.debug(i);
          });
        }
    

提交回复
热议问题