1
我需要为每个Restangular请求设置超时并在收到成功响应时将其取消。问题是请求拦截器中的访问响应如何?Restanglar。来自请求拦截器的捕获响应
我需要为每个Restangular请求设置超时并在收到成功响应时将其取消。问题是请求拦截器中的访问响应如何?Restanglar。来自请求拦截器的捕获响应
我如何解决它:
服务:
angular.module('mmn')
.factory('serverTimeout', function($timeout, $rootScope) {
var serverTimeout = {
request: function(config) {
config.timeout = $timeout(function() {
$rootScope.$broadcast('event:serverTimeout');
}, 30000);
return config;
},
response: function(response) {
$timeout.cancel(response.config.timeout);
return response;
}
};
return serverTimeout;
});
的App.config:
$httpProvider.interceptors.push('serverTimeout');
App.run:
//watch serverTimeout event
$rootScope.$on('event:serverTimeout', function(){
//your handler here
});