【发布时间】:2015-04-15 15:01:04
【问题描述】:
我正在使用 Angular 1.3.15,也尝试过 1.2.28 以及 angular bootstrap。昨晚,在将 Chrome 更新到 v42.0.2311.90 后,我突然开始看到大量的角度 itkn 错误:
Error: [$injector:itkn] Incorrect injection token! Expected service name as string, got function ()
http://errors.angularjs.org/1.3.15/$injector/itkn?p0=function%20()
at REGEX_STRING_REGEXP (angular.min.js?bust=undefined:63)
at Object.invoke (angular.min.js?bust=undefined:4189)
at angular.min.js?bust=undefined:6525
at forEach (angular.min.js?bust=undefined:323)
at Object.<anonymous> (angular.min.js?bust=undefined:6523)
at Object.invoke (angular.min.js?bust=undefined:4204)
at Object.enforcedReturnValue [as $get] (angular.min.js?bust=undefined:4056)
at Object.invoke (angular.min.js?bust=undefined:4204)
at angular.min.js?bust=undefined:4021
at Object.getService [as get] (angular.min.js?bust=undefined:4162)
这在更新 Chrome 之前没有发生,但我想我不能说这肯定是相关的。
经过一探究竟,我发现任何这样定义的指令:
.directive('modalTransclude', function () {
return {
// directive code
};
})
将导致此itkn 错误。我 console.logged key 在 $inject 迭代器中的角度,它返回指令本身的功能,而不仅仅是明确意图的字符串。
我发现将函数包装在一个数组中,即使没有定义注入的任何字符串,它也可以解决问题:
.directive('modalTransclude', [function () {
return {
// directive code
};
}])
但是,这个错误在 angular bootstrap 网站上没有发生,我在 angular 1.3 和 1.2 版本上都试过了。
我将继续寻找我的应用所特有的任何原因,但有人知道是什么原因造成的吗?
【问题讨论】:
-
Chrome 上发生了同样的事情,尽管只是针对我的引导模式。刚刚在 Firefox 上测试,他们似乎在那里工作
-
我可以确认这个指令问题只会影响我的角度引导程序。我自己的任何自定义指令都可以正常工作,无论是否带括号。
-
您的 chrome 中是否安装了 ng-inspector.org?对我来说,如果我关闭 ng-inspector,一切都会恢复到正常模式。不知道这到底是什么原因,没有时间深入研究。这种行为对我来说也是最近才出现的。
-
我愿意!我不知道为什么我没有想到这一点。这解决了问题!如果您想将此作为答案发布,我会接受。
-
完成。如果有人可以调查原因会很好。
标签: angularjs angular-bootstrap