是否可以使用angularjs拦截器阻止请求?
$provide.factory('myHttpInterceptor',function($q,someService) { return { 'request': function(config) { // here I'd like to cancel a request depending of some conditions } } }); $httpProvider.interceptors.push('myHttpInterceptor');
在1.1.5及更高版本中,您可以使用配置对象的“timeout”属性.
原文链接:https://www.f2er.com/angularjs/143275.htmltimeout – {number|Promise} – timeout in milliseconds,or promise that
should abort the request when resolved.
简单的例子:
$provide.factory('myHttpInterceptor',someService) { return { 'request': function(config) { var canceler = $q.defer(); config.timeout = canceler.promise; if (true) { // Canceling request canceler.resolve(); } return config; } } }); $httpProvider.interceptors.push('myHttpInterceptor');