在AngularJS中的$http请求期间显示微调器GIF?

我正在使用AngularJS的$http服务发出Ajax请求

在执行Ajax请求时,如何显示微调器GIF(或其他类型的忙指示器)

我在AngularJS文档中没有看到类似于ajaxstartevent的东西

这实际上取决于您的特定用例,但一种简单的方法将遵循如下模式:

.controller('MainCtrl',function($scope,myService){
$scope.loading=true;
myService.get().then(函数(响应){
$scope.items=response.data;
},功能(回应){
//TODO:以某种方式处理错误
}).最后(函数(){
//无论成功或失败都被召唤
$scope.loading=false;
});
});

然后在模板中对其作出反应:

<div class=“微调器”ng show=“加载”&gt&lt/部门>
<div ng repeat=“items中的item>{{item.name}}</div>

发表评论