angular-busy icon indicating copy to clipboard operation
angular-busy copied to clipboard

Allow multiple promises at a time??

Open msnpr567 opened this issue 11 years ago • 4 comments

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?

msnpr567 avatar Dec 18 '14 07:12 msnpr567

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 avatar Dec 18 '14 14:12 cgross

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

cgross avatar Dec 18 '14 14:12 cgross

@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.

naysayer avatar Jan 09 '15 23:01 naysayer

@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.

fabiosussetto avatar Jan 10 '15 14:01 fabiosussetto