Javascript 装饰$errorProvider时的循环引用

Javascript 装饰$errorProvider时的循环引用,javascript,angularjs,error-handling,circular-dependency,Javascript,Angularjs,Error Handling,Circular Dependency,在我正在从事的一个项目中,我正在按照项目负责人的要求实施一个开发人员通知系统。其工作方式是,如果发生前端错误,开发团队将收到一封错误电子邮件 但是,在我当前的实现中,似乎存在以下循环依赖关系: $rootScope在相关的侧边栏上再多看一眼,我就想到了。基本上,我必须使用$injector才能获得$http服务的实例句柄 (function() { 'use strict'; // Using .config to 'decorate' the exception handler

在我正在从事的一个项目中,我正在按照项目负责人的要求实施一个开发人员通知系统。其工作方式是,如果发生前端错误,开发团队将收到一封错误电子邮件

但是,在我当前的实现中,似乎存在以下循环依赖关系:


$rootScope在相关的侧边栏上再多看一眼,我就想到了。基本上,我必须使用
$injector
才能获得
$http
服务的实例句柄

(function() {
   'use strict';

    // Using .config to 'decorate' the exception handler.
    angular.module('app').config(function($provide) {
        $provide.decorator('$exceptionHandler', ['$delegate', '$injector', dispatchErrorEmail]);
    });

    function dispatchErrorEmail($delegate, $injector) {
        return function (exception, cause) {
            // Execute default implementation.
            $delegate(exception, cause);

            // Angular exceptions fail softly, but generate an error email.
            var $http = $injector.get('$http');
            var args = {
                'exception': exception,
                'cause': cause
            };
            $http.post('/api/admin/ErrorNotification', args);
        };
    }
})();

这并不能解释为什么
$rootScope
潜入
$exceptionHandler
服务;我想我必须相信它确实存在。

我也有类似的问题,你的帖子帮助我找到了解决办法。我有一个公共库,用于几乎所有的公共页面活动,如显示toast和管理加载指示器。您的解决方案帮助使用喷油器访问该服务。希望这对其他人有帮助

// custom exception handling
module.config(function ($provide) {
    $provide.decorator('$exceptionHandler', ['$delegate', '$injector', function ($delegate, $injector) {
        return function (exception, cause) {
            $delegate(exception, cause);
            var common = $injector.get('common');
            common.toast('Whoops, an error occurred!');
            common.loading(false);
        };
    }]);
});
// custom exception handling
module.config(function ($provide) {
    $provide.decorator('$exceptionHandler', ['$delegate', '$injector', function ($delegate, $injector) {
        return function (exception, cause) {
            $delegate(exception, cause);
            var common = $injector.get('common');
            common.toast('Whoops, an error occurred!');
            common.loading(false);
        };
    }]);
});