Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angularjs 如何为特定API调用禁用$http.pendingRequests.length?_Angularjs_Http_Model View Controller_Http Headers - Fatal编程技术网

Angularjs 如何为特定API调用禁用$http.pendingRequests.length?

Angularjs 如何为特定API调用禁用$http.pendingRequests.length?,angularjs,http,model-view-controller,http-headers,Angularjs,Http,Model View Controller,Http Headers,我有angularjs中的控制器,其中编写了一个逻辑来显示页面中的加载程序 appCtrl.js $rootScope.loaderExceptionCount = 0 ; $scope.isAnythingLoading = function() { console.log($http.pendingRequests, $http); return $http.pendingRequests.length > $rootScope.loaderEx

我有angularjs中的控制器,其中编写了一个逻辑来显示页面中的加载程序

appCtrl.js

$rootScope.loaderExceptionCount = 0 ;
    $scope.isAnythingLoading = function() {
        console.log($http.pendingRequests, $http);
        return $http.pendingRequests.length > $rootScope.loaderExceptionCount;
    };
和index.html作为

<div ng-show="isAnythingLoading()" class="pageLoader">
        <div class="loaderBackdrop"></div>
            <div class="sk-wave">
                    <div class="sk-rect sk-rect1"></div>
                    <div class="sk-rect sk-rect2"></div>
                    <div class="sk-rect sk-rect3"></div>
                    <div class="sk-rect sk-rect4"></div>
                    <div class="sk-rect sk-rect5"></div>
            </div>
        </div>
<div ui-view=""></div>

有一个post-API调用,我不想对其使用show-loader。我们可以禁用特定API调用的加载程序吗

可以通过以下方法解决

var skippedUrls = ['...'];
$scope.isAnythingLoading = function() {
  var reqCount = $http.pendingRequests
    .filter(function (req) {
      return !skippedUrls.includes(req.url);
    })
    .length;
  return  reqCount > $rootScope.loaderExceptionCount;
};
明确说明
$http.pendingRequests
目的:

当前挂起请求的配置对象数组。这是 主要用于调试目的

更可靠的解决方案包括执行与上述相同操作的拦截程序、保存加载状态的独立服务和将状态绑定到UI元素的指令。

可以通过

var skippedUrls = ['...'];
$scope.isAnythingLoading = function() {
  var reqCount = $http.pendingRequests
    .filter(function (req) {
      return !skippedUrls.includes(req.url);
    })
    .length;
  return  reqCount > $rootScope.loaderExceptionCount;
};
明确说明
$http.pendingRequests
目的:

当前挂起请求的配置对象数组。这是 主要用于调试目的


更可靠的解决方案包括执行与上述相同操作的
$http
拦截器、保存加载状态的独立服务和将状态绑定到UI元素的指令。

可能吗?可能吗?