2
在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);
}
};
});
的'params'对象将被解释为查询字符串'GET'请求,对不对?将'scope'传递给'params'对象是否合理? – 2015-02-06 04:02:48
我想到了这一点,以及你可以在请求实际发送前删除config.params.origScope' – 2015-02-06 04:08:25
基本上如我所说,将范围传递到工厂或服务并不是一个好的设计。 – 2015-02-06 04:09:34