Angularjs 如何为特定API调用禁用$http.pendingRequests.length?
我有angularjs中的控制器,其中编写了一个逻辑来显示页面中的加载程序 appCtrl.jsAngularjs 如何为特定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
$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元素的指令。可能吗?可能吗?