Sunday 21 May 2017

typescript promise return after loop

I am trying to return after all the calls to an external service are done but my code is just flying through the for loop and returning. I cannot do a promise.all here as I need some values obtained in the loop. Is there an easy way to do this in typescript/angular2?

var ret = [];
for (var l in users){
   var userLicense = users[l].licenseNumber;
   this.callExternalService(userLicense).subscribe(response=>{
      ret.add(response+userLicense);
   }
}
resolve(ret);



via spartikus

No comments:

Post a Comment