【发布时间】:2015-02-06 12:31:44
【问题描述】:
在AngularJS响应错误拦截器中,有没有办法检索当前请求的范围?
module.controller('myController', function($http, $scope) {
$scope.getData = function() {
// This scope is which the request is originated
$http.get('http://www.example.com/get', {
params: { 'id': '1234' }
}).success(function(data, status, headers, config) {
// ...
}).error(function(data, status, headers, config) {
// ...
});
}
});
module.factory('myInterceptor', function($q) {
return {
'responseError': function(response) {
// How can I get the scope of 'myController' here?
return $q.reject(response);
}
};
});
【问题讨论】:
标签: ajax angularjs interceptor angular-http-interceptors