错误如下:
Uncaught Error: [$injector:modulerr] Failed to instantiate module ng due to:
Error: [$injector:strictdi] function($provide) is not using explicit annotation and cannot be invoked in strict mode
http://errors.angularjs.org/1.5.8/$injector/strictdi?p0=function(%24provide)
at localhost/build/js/app-vendor.js:53360:12
at Function.annotate [as $$annotate] (localhost/build/js/app-vendor.js:57244:17)
at injectionArgs (localhost/build/js/app-vendor.js:57971:36)
at Object.invoke (localhost/build/js/app-vendor.js:58002:18)
at runInvokeQueue (localhost/build/js/app-vendor.js:57903:35)
at localhost/build/js/app-vendor.js:57912:11
at forEach (localhost/build/js/app-vendor.js:53613:20)
at loadModules (localhost/build/js/app-vendor.js:57893:5)
at createInjector (localhost/build/js/app-vendor.js:57815:19)
at doBootstrap (localhost/build/js/app-vendor.js:55050:20)
http://errors.angularjs.org/1.5.8/$injector/modulerr?p0=ng&p1=Error%3A%20%5….com%3A21293%2FWebGui%2Fbuild%2Fjs%2Fapp-vendor.js%3A55050%3A20)
通常你知道该怎么做:搜索没有注释的函数。但是:
- 我做了,但是找不到bug 我通过
- 堆栈跟踪没有显示任何内容,只有angular代码
- 查找
function($provide)
-的发生无效
ngAnnotate
运行我的代码我捕获了抛出的异常,在堆栈跟踪的某处有一个:
var injector = createInjector(modules, config.strictDi);
injector.invoke(['$rootScope', '$rootElement', '$compile', '$injector',
function bootstrapApply(scope, element, compile, injector) {
scope.$apply(function() {
element.data('$injector', injector);
compile(element)(scope);
});
}]
);
return injector;
和
if (!($inject = fn.$inject)) {
$inject = [];
if (fn.length) {
if (strictDi) {
if (!isString(name) || !name) {
name = fn.name || anonFn(fn);
}
throw $injectorMinErr('strictdi',
'{0} is not using explicit annotation and cannot be invoked in strict mode', name);
}
argDecl = extractArgs(fn);
forEach(argDecl[1].split(FN_ARG_SPLIT), function(arg) {
arg.replace(FN_ARG, function(all, underscore, name) {
$inject.push(name);
});
});
}
fn.$inject = $inject;
}
从我在手表窗口看到的&堆栈跟踪它发生在应用程序的某个地方,其中$injector.invoke
被调用函数作为参数。但是我真的翻遍了文件,找不到任何这样的电话。
我也有这个问题,并发现它是通过禁用Chrome angularjs调试器"Batarang"来解决的。