I am making a page with AngularJS and some jQuery plugins in which the angular-js controller initializes its model by calling some servlet methods via ajax asynchronously. I want to show a loading gif when the first ajax call starts and hide it when the last ajax call finishes.
Since I don't know which will be the last ajax call to finish, I cannot know where to place the instructions to hide the loading gif. How can I achieve this behavior?
A code example of what i want:
myApp.controller("adminCtrl", function($scope, $http) {
$scope.initData1 = function() {
/* is this the first call? then show the gif */
$http(...).success(function() { /* is this the last response received? then hide the gif */});
}
$scope.initData2 = function() {
/* is this the first call? then show the gif */
$http(...).success(function() { /* is this the last response received? then hide the gif */});
}
$scope.initData3 = function() {
/* is this the first call? then show the gif */
$http(...).success(function() { /* is this the last response received? then hide the gif */});
}
initData1();
initData2();
initData3();
}
I hope you understand my problem and know any way to achieve this.