由于函数($ provide)未使用显式注释而无法实例化模块ng

时间:2016-10-20 14:33:03

标签: javascript angularjs

所以这是错误:

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
  • 我通过ngAnnotate
  • 运行我的代码
  • 堆栈跟踪什么都没说,只有角度代码
  • 搜索function($provide)的出现 - 徒劳无功

我抓住了抛出的异常,在堆栈跟踪的某个地方有一个:

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被调用函数作为参数。但我老实说搜索文件,我找不到任何这样的电话。

Angular 1.5.8正在发生。

1 个答案:

答案 0 :(得分:0)

我也遇到了这个问题,发现通过禁用Chrome angularjs调试器“ Batarang”可以解决此问题。