Javascript 修复在重写的$exceptionHandler中使用$http时的循环依赖性?
我已经通过注入$http覆盖了$exceptionHandler。我这样做是因为我在服务器上记录了一个arrorJavascript 修复在重写的$exceptionHandler中使用$http时的循环依赖性?,javascript,angularjs,Javascript,Angularjs,我已经通过注入$http覆盖了$exceptionHandler。我这样做是因为我在服务器上记录了一个arror Module.factory('$exceptionHandler', ['$http', function ($http) { "use strict"; //code } 但是,我还有一个拦截器来添加my$httpProvider: Module.config(['$httpProvider', function($httpProvider) { $htt
Module.factory('$exceptionHandler', ['$http', function ($http) {
"use strict";
//code
}
但是,我还有一个拦截器来添加my$httpProvider:
Module.config(['$httpProvider', function($httpProvider) {
$httpProvider.interceptors.push('special-http');
}]);
这就是拦截器(我用工厂包装):
编辑
修复“$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
Uncaught错误:[$injector:cdep]找到循环依赖项:$http您可以在以后注入$injector
以获取$http
:
Module.factory('$exceptionHandler', ['$injector', function ($injector) {
"use strict";
return function (exception, cause) {
var $http = $injector.get('$http');
// code
};
}
请参见您可以在以后注入$injector
以获取$http
:
Module.factory('$exceptionHandler', ['$injector', function ($injector) {
"use strict";
return function (exception, cause) {
var $http = $injector.get('$http');
// code
};
}
请参见这可能是一件愚蠢的事情,但工厂定义中的字符串“$http”中没有空格吗?@Wawy如果有,我会脸红的。@Wawy谢谢,你能看看我对循环依赖的编辑吗http依赖于exceptionHandler已经,你不能将http注入exceptionHandler。@mpm ah。。那么,你知道我需要什么方法在出错时登录到服务器吗?这可能是一件愚蠢的事情,但工厂定义中的字符串“$http”中没有空格吗?@Wawy如果有,我会脸红的。@Wawy谢谢,你能看看我关于循环依赖的编辑吗http依赖于exceptionHandler已经,您不能将http注入exceptionHandler。@mpm-ah。。那么,你知道我需要什么方法在出错时登录服务器吗?我很确定你会遇到完全相同的问题。不,我已经在生产中运行了几个月:)@khellang令人印象深刻非常感谢Kristian!快乐的角度编码!看起来总是
在1.2.0:)中被重命名为最后
。@fatmatto:谢谢你的评论。这对我帮助很大。我很确定你会得到完全相同的问题。不,我已经在生产中运行了几个月:)@khellang令人印象深刻非常感谢克里斯蒂安!快乐的角度编码!看起来总是
在1.2.0:)中被重命名为最后
。@fatmatto:谢谢你的评论。这对我帮助很大。