所以我拦截了一个角度$ http请求和响应。可以说,如果我有一个响应错误,我想重新激活我的$ http调用。问题是我需要在我的拦截器中注入$ http服务,并创建一个循环依赖。这是我的代码中的CoffeeScript简化版本:
retryModule = angular.module('retry-call', [])
retryModule.factory 'RetryCall', ($q, $http)->
# More object keys
'responseError': (response)=>
# Retry request if failed
# I need a different way of invoking $http() to avoid circular dependency
$http(response.config)
$q.reject(response)
retryModule.config ['$httpProvider', ($httpProvider)->
$httpProvider.interceptors.push('RetryCall');
]
感谢
检查这个答案:http://stackoverflow.com/questions/21119016/is-there-a-way-to-request-http-for-an-interceptor/21119959#21119959 –
我希望我想到这一点。现在我感到哑巴,哈哈。 –