This is the deal.
I what to show a spinner when doing a $http call, but the problem here is that I have multiple calls at ones, so the examples I found here didn't help.
Did anyone have a solution for this?
A way to stack the calls so the spinner remains until the last call finish? I hope to make my point.
Im doing this.
angular.module('moduleName', []).
factory.("SomeService", function () {
return:{
getResources(params) {
/* do the $http call */
}
}
}).
controller("SomeCtrl", function (SomeService) {
SomeService.getResources(params)
}).
controller("OtherCtrl", function (SomeService) {
SomeService.getResources(params)
});
The 2 controllers may call the service at the same time and the may get diferent responce.
All
$http
calls in Angular return a promise.The
$q
service doesn't have all the bells and whistles of the Q library, which it is based, but if you look at the docs, it does have anall
method that can be used to give you the functionality you want.Here's how you could use it:
You can do this by using interceptor and passing one flag in the header of each API.What all you need to do it.Add one parameter in each $http call.
Than capture it in the interceptor Request method by using property config.headers.{{Parameter}}.On the basis of this flag broadcast one event for showing wait image.
Use a variable that is initialized to the number of calls you are making. In each of the callbacks for the AJAX calls, call a function that decrements the value of this variable and if it's zero, removes the spinner.