将$ http注入角度工厂($ exceptionHandler)会导致循环依赖

Fut*_*oad 17 circular-dependency angularjs

当我尝试将$ http注入到重写的工厂时,我得到错误:

未捕获错误:[$ injector:cdep]找到循环依赖项:$ http < - $ exceptionHandler < - $ rootScope

AngularModule.factory('$exceptionHandler',  function ($http) {
Run Code Online (Sandbox Code Playgroud)

任何想法如何解决?如果我使用[]注入,$ http是未定义的

edit_ _ __ _ __ _ __ _ __ _ __ _ _

根据下面的答案,我试过:

MyModule.config(function($provide, $http) {
    $provide.decorator("$exceptionHandler", function($delegate) {
        return function(exception, cause) {..
Run Code Online (Sandbox Code Playgroud)

但我仍然得到循环错误:

未捕获错误:[$ injector:cdep]找到循环依赖项:$ http < - $ exceptionHandler < - $ rootScope

dnc*_*253 26

注入$injector然后$http从那里获得服务.像这样的东西:

AngularModule.factory('$exceptionHandler',  function ($injector) {
    var $http = $injector.get("$http");
Run Code Online (Sandbox Code Playgroud)

请参阅https://groups.google.com/forum/#!topic/angular/lbFY_14ZtnU/discussion

但是,这将完全覆盖$exceptionHandlerAngular提供的功能.如果您只想将服务器端日志添加到现有功能,请参阅有关扩充功能的此问题$exceptionHandler.

  • 不幸的是我不能这样做:**var $ http = $ injector.get("$ http");**我收到错误**$ http < - $ exceptionHandler < - $ rootScope** (6认同)