角/第三方模块对网络流量监控有支持吗?
我想要建立的是类似于$watch的东西,仅用于网络流量。
$scope.$watch('xhrTraffic', function(newval) {
newval - true when traffic starts/false when traffic ends
});我希望能够控制浏览器什么时候在使用网络,什么时候不使用。
发布于 2015-04-15 07:32:38
在我看来,你需要像这这样的东西
更新
此代码将有助于管理XHR请求:
(function (){
'use strict';
angular.module( 'security.http-interceptor', [] )
.factory( 'securityInterceptor', ['$injector', '$q', '$rootScope', function ( $injector, $q, $rootScope ){
return {
'request' : function ( config ){
// do something on success
return config;
},
// optional method
'requestError' : function ( rejection ){
// do something on error
if ( canRecover( rejection ) ) {
return responseOrNewPromise
}
return $q.reject( rejection );
},
// optional method
'response' : function ( response ){
// do something on success
return response;
},
// optional method
'responseError' : function ( rejection ){
// do something on error
if ( canRecover( rejection ) ) {
return responseOrNewPromise
}
return $q.reject( rejection );
}
};
}] )
// We have to add the interceptor to the queue as a string because the interceptor depends upon service instances that are not available in the config block.
.config( ['$httpProvider', function ( $httpProvider ){
$httpProvider.interceptors.push( 'securityInterceptor' );
}] );
}());之前的链接是AUTH请求检查的一个例子。
有关拦截器的更多信息,请阅读这里
https://stackoverflow.com/questions/29644055
复制相似问题