从AngularJS的加载拦截器中排除特定的URL

时间:2018-12-21 10:27:49

标签: angularjs

我正在使用拦截器来加载微调器,这很棒。但是,我想从显示微调器中排除特定的http请求url。任何可能的想法如何解决此问题?

控制器

 $rootScope.$on('loading:progress', function (config){
      $scope.spinner=true;
  });

  $rootScope.$on('loading:finish', function (){
   $scope.spinner=false;
  });

工厂/配置

app.factory('httpInterceptor', ['$q', '$rootScope',
function ($q, $rootScope) {
    var loadingCount = 0;

    return {
        request: function (config) {
            if(++loadingCount === 1)

            $rootScope.$broadcast('loading:progress');
            return config || $q.when(config);

        },

        response: function (response) {
            if(--loadingCount === 0) $rootScope.$broadcast('loading:finish');
            return response || $q.when(response);
        },

        responseError: function (response) {
            if(--loadingCount === 0) $rootScope.$broadcast('loading:finish');
            return $q.reject(response);
        }
    };
}]).config(['$httpProvider', function ($httpProvider) {
$httpProvider.interceptors.push('httpInterceptor');}]);

0 个答案:

没有答案