修复在覆盖$exceptionHandler中使用$http时的循环依赖关系
Fixing circular dependancy when using $http inside the overriden $exceptionHandler?
我通过注入$http覆盖了$exceptionHandler。我这样做是因为我将一个 arror 登录到服务器。
Module.factory('$exceptionHandler', ['$http', function ($http) {
"use strict";
//code
}
但是,我也有一个拦截器来添加我的$httpProvider:
Module.config(['$httpProvider', function($httpProvider) {
$httpProvider.interceptors.push('special-http');
}]);
这是拦截器(我包装在工厂中):
Module.factory('special-http', ['$templateCache', function($templateCache) {
"use strict";
return {
'request': function(config) {
if ($templateCache.get(config.url)){
return config;
}
//some logic
return config;
}
}
}]);
EDIT______
修复"$http"的名称后
我现在收到此错误:
Uncaught Error: [$injector:cdep] Circular dependency found: $http <- $exceptionHandler <- $rootScope
http://errors.angularjs.org/1.2.1/$injector/cdep?p0=%24http%20%3C-%20%24exceptionHandler%20%3C-%20%24rootScope
您可以注入$injector
以便稍后获得$http
:
Module.factory('$exceptionHandler', ['$injector', function ($injector) {
"use strict";
return function (exception, cause) {
var $http = $injector.get('$http');
// code
};
}
看到这个小提琴
相关文章:
- 如何让foreach循环等待$http.get完成后再继续
- JavaScript 中的 http request in while 循环
- $http在什么时候触发摘要循环开始
- node.js:在for循环中进行http调用
- 循环AngularJS$http调用-TypeError:对象不是函数
- 在绑定到内部$http函数时运行无限摘要循环
- 循环遍历 Angular HTTP 请求中的对象,等到响应后再运行下一个循环
- $http调用似乎产生了无限$digest循环
- $http循环请求并在Angularjs中组装数据
- Angular http GET循环使用新的URL作为响应
- 为什么 Angular 摘要循环在 UI 事件、$timeout和$http上有所不同
- Node.js http.get in 循环仅获取最后一项
- 使用javascript的无限循环(Angular NgFor和http请求)
- 从http服务器获取图像并在智能电视中循环显示
- 循环嵌套$http js函数
- AngularJS: forEach http get data -等待其他方法,直到所有来自循环的数据被加载
- Node.js -使用http.get循环遍历要保存在本地的JSON文件列表
- 在每个循环中链接angularjs $http请求
- Meteor / Node.js:多个http请求在一个for循环中,均匀地跨越一个定时间隔
- 循环多个HTTP请求并组合结果