2014-03-31 23 views
0

我已通过注入$ http来覆盖$ exceptionHandler。我这样做是因为我记录了一个arror到服务器。

Module.factory('$exceptionHandler', ['$http', function ($http) { 
    "use strict"; 
//code 
} 

但是我也有一个拦截器来添加我的$ httpProvider:

Module.config(['$httpProvider', function($httpProvider) { 
     $httpProvider.interceptors.push('special-http'); 
    }]); 

这是拦截器(我包裹在一个工厂):

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 
+0

这可能是一个愚蠢的事情,但是是不是有空间字符串“$ HTTP”在工厂的定义? – Wawy

+0

@Wawy如果是我要脸红.. – FutuToad

+0

@Wawy谢谢,你可以看看我的编辑关于**循环依赖** – FutuToad

回答

5

您可以注入$injector后得到$http

Module.factory('$exceptionHandler', ['$injector', function ($injector) { 
    "use strict"; 

    return function (exception, cause) { 
     var $http = $injector.get('$http'); 
     // code 
    }; 
} 

this fiddle

+0

我很确定你会得到完全相同的问题。 – mpm

+0

不,我一直在生产这个几个月:) – khellang

+0

@khellang令人印象深刻的很多谢谢克里斯蒂安!快乐的角码编码! – FutuToad