Angular - 找到循环依赖

时间:2016-01-19 17:20:14

标签: angularjs ng-dialog

我收到了上述错误。以下是一些简化的代码片段。 应用程序:

app.config(
function ($httpProvider, $translateProvider, $translatePartialLoaderProvider) {
    $translateProvider.preferredLanguage(lang);
    $translateProvider.useLoader('$translatePartialLoader', {
        urlTemplate: 'api/PartialTranslationLoad?lang={lang}&table={part}'
    });
    $translatePartialLoaderProvider.addPart('...');
    $translatePartialLoaderProvider.addPart('...');
    $translateProvider.useSanitizeValueStrategy('sanitize');

    $httpProvider.interceptors.push('APIInterceptor');
  }
);

模块配置:

classes = angular.module("app.classes", []);

classes.service('APIInterceptor', function ($q, $rootScope, $location, $window, $injector, ngDialog) {
    ......
}

拦截器服务在app.classes模块中:

is(A == b)

错误:

  

找到循环依赖项:$ http< - $ templateRequest< - $ compile< - ngDialog< - APIInterceptor< - $ http< - $ translatePartialLoader

如果我不将ngDialog注入我的拦截器,一切都很好。有人可以解释为什么我得到循环依赖性错误?

由于

1 个答案:

答案 0 :(得分:5)

核心问题是:

  1. 0 info it worked if it ends with ok 1 verbose cli [ 'node', '/usr/local/bin/npm', 'test' ] 2 info using npm@2.11.3 3 info using node@v0.12.7 4 verbose stack Error: ENOENT, open '/Users/apps/Desktop/IOT/NodeJS/package.json' 4 verbose stack at Error (native) 5 verbose cwd /Users/apps/Desktop/IOT/NodeJS 6 error Darwin 15.0.0 7 error argv "node" "/usr/local/bin/npm" "test" 8 error node v0.12.7 9 error npm v2.11.3 10 error path /Users/apps/Desktop/IOT/NodeJS/package.json 11 error code ENOENT 12 error errno -2 13 error enoent ENOENT, open '/Users/apps/Desktop/IOT/NodeJS/package.json' 13 error enoent This is most likely not a problem with npm itself 13 error enoent and is related to npm not being able to find a file. 14 verbose exit [ -2, true ] 注入APIInterceptor
  2. ngDialog在内部注入ngDialog
  3. $http注入$http(因为您已通过APIInterceptor
  4. 添加了拦截器

    最简单的解决方案是在需要时使用$httpProvider手动检索$injector

    简单示例:

    ngDialog