答案是肯定的,我在这里试过:
var dependentApp = angular.module('dependency',[]).config(['$httpProvider', function($httpProvider) {
$httpProvider.interceptors.push(function ($q) {
return {
'request': function (config) {
console.log('request intercept');
},
'response': function (response) {
console.log('response intercept');
}
};
});
}]);
var app = angular.module('myapp', ['dependency']);
app.controller('mycontroller', ['$scope', '$http', function ($scope, $http) {
$http.get('http://www.google.com');
}]);
我看到请求被拦截了。这是小提琴:http: //jsfiddle.net/6dbgo6pt/1/