cgross / angular-busy

Show busy/loading indicators on any element during $http requests (or any promise).
http://cgross.github.io/angular-busy/demo
MIT License
1.44k stars 256 forks source link

Allow multiple promises at a time?? #53

Open msnpr567 opened 9 years ago

msnpr567 commented 9 years ago

I want to use angular-busy loader for a time of 5 successive requests , can i use it ?? then how?? (or) can i include multiple promises at a time?

cgross commented 9 years ago

If you are using a regular promise chain then just assign the promise from the last then() to cg-busy like:

$scope.myBusyPromise = $http(...).then(function(data){
    ...
}).then(function(data){
   ...
}).then(function(data){
   ...
}).then(function(data){
   ....
});
cgross commented 9 years ago

If they're all-at-once instead of in-a-row then just use $q.all()

naysayer commented 9 years ago

@cgross could you give an example of how to use $q.all()? I am in a situation where I have a dynamic number of calls being made and would like the loading icon to be displayed until they are all complete. Thanks in advance.

fabiosussetto commented 9 years ago

@naysayer example:

// controller
$scope.allDonePromise = $q.all([promise1, promise2, ...]);

// template
<div cg-busy="allDonePromise">

The spinner will be shown until all the promises will be resolved. Note the promises cab be run in parallel. From Angular docs: "$q.all(): Combines multiple promises into a single promise that is resolved when all of the input promises are resolved." CgBusy is very cool because he doesn't care about http requests, all it cares about are promises.