我收到了上述错误。以下是一些简化的代码片段。 应用程序:
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注入我的拦截器,一切都很好。有人可以解释为什么我得到循环依赖性错误?
由于
答案 0 :(得分:5)
核心问题是:
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
ngDialog
在内部注入ngDialog
$http
注入$http
(因为您已通过APIInterceptor
最简单的解决方案是在需要时使用$httpProvider
手动检索$injector
。
简单示例:
ngDialog