Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I use Async.js library in AngularJS?

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?

like image 484
Mukund Kumar Avatar asked Aug 04 '14 10:08

Mukund Kumar


People also ask

Can I use async await 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.

Is AngularJS asynchronous?

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.

Is AngularJS synchronous or asynchronous?

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.

What is $q in AngularJS?

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.


1 Answers

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/

like image 198
Yc Zhang Avatar answered Oct 01 '22 14:10

Yc Zhang