[英]How to know that angular completed all processing and rendering
I need to stop progress bar.我需要停止进度条。 If I have several
http
request, how can i know when all threads completed, and all responses are rendered.如果我有多个
http
请求,我如何知道所有线程何时完成以及所有响应何时呈现。 I tried to use $httpProvider.interceptors
on response, but i can not know whether this is the last http
response or not.我尝试在响应中使用
$httpProvider.interceptors
,但我不知道这是否是最后一个http
响应。 And also you can not know when this last response will be rendered.而且您也不知道什么时候会呈现最后一个响应。
You can track the pending request by http.pendingRequests
in your interceptor like您可以通过拦截器中的
http.pendingRequests
跟踪待处理的请求,例如
angular.module('myApp').factory('myHttpResponseInterceptor', function($q, $location, $injector, $rootScope){
var _http = null;
return {
request: function(config){
$rootScope.$broadcast("loader_show");
return config;
},
response: function(response){
_http = _http || $injector.get('$http');
if(_http.pendingRequests.length < 1){
$rootScope.$broadcast("loader_hide");
}
return response;
},
responseError: function (response) {
_http = _http || $injector.get('$http');
if(_http.pendingRequests.length < 1){
$rootScope.$broadcast("loader_hide");
}
console.log("response rejected in interceptor");
return $q.reject(response);
}
};
});
I have used this in my project and it works just fine.我在我的项目中使用了它,它工作得很好。
Hope it helps you too.希望对你也有帮助。
你可以使用angular-busy或ngProgress 之类的模块来做同样的事情。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.