在角$ HTTP请求中显示微调GIF [英] Showing Spinner GIF during $http request in angular
本文介绍了在角$ HTTP请求中显示微调GIF的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我使用的角度对 $ HTTP
服务,使一个Ajax请求。
I am using the $http
service of angular to make an ajax request.
如何显示Ajax请求期间装载机GIF?
How to show a loader gif during the ajax request?
我看不到任何文档 ajaxstartevent
或类似的事件。
I don't see any ajaxstartevent
or similar event in documentation.
推荐答案
下面是电流过去AngularJS咒语:
Here are the current past AngularJS incantations:
angular.module('SharedServices', [])
.config(function ($httpProvider) {
$httpProvider.responseInterceptors.push('myHttpInterceptor');
var spinnerFunction = function (data, headersGetter) {
// todo start the spinner here
//alert('start spinner');
$('#mydiv').show();
return data;
};
$httpProvider.defaults.transformRequest.push(spinnerFunction);
})
// register the interceptor as a service, intercepts ALL angular ajax http calls
.factory('myHttpInterceptor', function ($q, $window) {
return function (promise) {
return promise.then(function (response) {
// do something on success
// todo hide the spinner
//alert('stop spinner');
$('#mydiv').hide();
return response;
}, function (response) {
// do something on error
// todo hide the spinner
//alert('stop spinner');
$('#mydiv').hide();
return $q.reject(response);
});
};
});
//regular angular initialization continued below....
angular.module('myApp', [ 'myApp.directives', 'SharedServices']).
//.......
这里是它(HTML / CSS)利用休息....
$('#mydiv').show();
$('#mydiv').hide();
切换它。注:以上的角模块在帖子开始使用
#mydiv {
position:absolute;
top:0;
left:0;
width:100%;
height:100%;
z-index:1000;
background-color:grey;
opacity: .8;
}
.ajax-loader {
position: absolute;
left: 50%;
top: 50%;
margin-left: -32px; /* -1 * image width / 2 */
margin-top: -32px; /* -1 * image height / 2 */
display: block;
}
<div id="mydiv">
<img src="lib/jQuery/images/ajax-loader.gif" class="ajax-loader"/>
</div>
这篇关于在角$ HTTP请求中显示微调GIF的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文