I have to call an api : /1/dir/{imgID}
many times(average 50 times) using variation in imgID
.
In node.js i can use Async.js library. Can I use this library in Angular side? If yes then give me some idea how is it possible and if no then give me some alternative idea so that i can use this in AngularJS?
Update: With newer version of Angular, we do not need to worry about promise returned from http(). We can still use async-await for other promise based logic though. Promises and callback functions are building blocks for writing asynchronous code in JavaScript.
In AngularJS, we have the $q object which is a service that helps to execute a function asynchronously and use values returned from these calls for further processing. This is an implementation of promise or deferred object.
AngularJs supports async requests by default. Show activity on this post. Ajax requests are always asynchronous. Angular exposes the $http service, which allows you to do all http requests to the server.
all() in AngularJS couldn't be simpler. $q is an Angular Service which facilitates running functions asynchronously. It's based on a library (Q) by Kris Kowal. $q. all() allows us to wait on an array (or object) of promises, $q.
Yes, you can.
Basically, you need to use $q.all(promises);
, which can combine multiple promises into a single promise that is resolved when all of the input promises are resolved.
Example: http://www.bennadel.com/blog/2772-exploring-asynchronous-promise-based-workflows-in-angularjs.htm
Document: https://docs.angularjs.org/api/ng/service/$q
Demo: http://bennadel.github.io/JavaScript-Demos/demos/error-workflow-promises-angularjs/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With