创建工厂“resInterceptor”,并使用在工厂外定义的函数(requestInterceptor,responseInterceptor)。它在函数内部发生错误'$ q is not defined'。但我只想这样做。请建议如何在requestInterceptor和responseInterceptor中访问$ q。
angular.module('resModule', ['ngResource', 'ngCookies'])
.factory('resInterceptor', ['$rootScope', '$q', '$location', resInterceptor]);
function resInterceptor($rootScope, $q, $location) {
return {
request: requestInterceptor,
response: responseInterceptor,
};
}
function requestInterceptor(config) {
return config || $q.when(config); //$q is not defined
}
function responseInterceptor(response) {
return response || $q.when(response);
}
requestInterceptor定义在不同的范围内。这显然不起作用。 –