我想提出一个页面AngularJS以及其中角JS控制器通过调用通过ajax一些servlet方法异步初始化其模型的一些jQuery插件。我想在第一次ajax调用开始时显示加载gif,并在最后一次ajax调用结束时将其隐藏。显示等待中的Gif为多个异步AJAX调用
因为我不知道这将是最后一个Ajax调用来完成,我不知道在哪里放置说明隐藏加载GIF。我如何实现这种行为?
的我想要什么的代码示例:
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();
}
我希望你明白我的问题,并知道任何方式来实现这一目标。
我接受@Valentin Waeselynck的答案,因为它是可重复使用的多个控制器(这是我的情况),也因为我不能肯定,如果使用的承诺Chandermani的答案会像IE8浏览器+工作(这也是我的情况)。尽管如此,我认为Chandermani对承诺的回答是现代浏览器的最佳方法。装载栏也很酷。 – 2014-09-30 16:19:07