【发布时间】:2014-03-31 07:41:02
【问题描述】:
我通过注入 $http 覆盖了 $exceptionHandler。我这样做是因为我在服务器上记录了一个错误。
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
【问题讨论】:
-
这可能是一件很傻的事情,但工厂定义中的字符串“$http”中没有空格吗?
-
@Wawy 如果是我会脸红..
-
@Wawy 谢谢,你能看看我关于循环依赖的编辑吗
-
http 已经依赖于 exceptionHandler,你不能将 http 注入到 exceptionHandler 中。
-
@mpm 啊..所以任何想法我需要什么方法在错误时登录到服务器?
标签: javascript angularjs