脚本宝典收集整理的这篇文章主要介绍了angular ajax loading,脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。
知识点:
AngularJS 中利用 Interceptors 来统一处理 HTTP 的错误
具体实现:
/**
拦截器 全局$http注入loading效果
*/
define(['jquery','Angular'], function($,angular){
angular.module('ajaxLoading', [])
.config(function($httpProvider) {
$httpProvider.interceptors.push('loadingInterceptor');
})
.directive('loading', function() {
return {
replace: true,
restrict: 'AE',
template:'<div class="back-layer"><div class="loading">'
+'<img src="images/729.GIF">'
+'</div></div>',
link: function($scope, $element, attrs) {
var top = $(window).height()/2 - 25;
var left = $(window).width()/2 - 25;
$('.loading').css({
top: top,
left: left
});
//$(tpl).appendTo('body');
}
};
})
.factory('loadingInterceptor', function($q, $rootScope) {
return {
request: function(config) {
$(".back-layer").show();
return config || $q.when(config);
},
response: function(response) {
$(".back-layer").hide();
return response || $q.when(response);
},
responseError: function(rejection) {
$(".back-layer").hide();
return $q.reject(rejection);
}
};
});
@H_446_126@
})
以上是脚本宝典为你收集整理的angular ajax loading全部内容,希望文章能够帮你解决angular ajax loading所遇到的问题。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。