加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

angular ajax loading

发布时间:2020-12-17 09:20:53 所属栏目:安全 来源:网络整理
导读:知识点: AngularJS 中利用 Interceptors 来统一处理 HTTP 的错误 具体实现: /** 拦截器 全局$http注入loading效果 */ define(['jquery','angular'],function($,angular){ angular.module('ajaxLoading',[]).config(function($httpProvider) { $httpProvider

知识点:
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);
    }
  };
});

})

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读