Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

239
Views
¿Cómo hacer llamadas asíncronas en angularJS usando $promise?

Necesito hacer varias llamadas a una API y concatenar los resultados. estoy usando angularjs

 $scope.myFunction = function() { let res; for (//some condition) { let data = MyService.query(); data.$promise.then(function(r){ // here I receive the response from the api and I "concatenate" the result in a variable res += r.someValue; } } // here I need to do something with **res** when all the api calls are done }

el problema es que el código fuera del bucle for se ejecuta antes de que todas las llamadas a la API devuelvan un resultado.

¿Cómo puedo hacer que el código después del ciclo for espere a que se ejecute todo el código dentro del ciclo y la variable res esté completa? Usar async/await no funciona porque recibo este error

 "angular.js:12808 ReferenceError: regeneratorRuntime is not defined"

y por el momento no puedo agregar paquetes a package.json.

about 4 years ago · Santiago Gelvez
1 answers
Answer question

0

Puedes usar Promise.all algo como

 $scope.myFunction = function() { let res=[]; for (//some condition) { let data = MyService.query(); let respPromise= data.$promise.then(function(r){ // return the response return r.someValue; }) res.push(respPromise); } Promise.all(res).then(data=>{ console.log(data);//data should contains all the responses here }) }

apilado de trabajo

about 4 years ago · Santiago Gelvez Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!