问题描述
我收到错误消息找不到指令‘ngClass’所需的控制器‘gssResponseGroup’!"使用链接的 Plunker 文件时.问题是,有时它工作得很好,有时我会收到此错误.我的猜测是指令的加载/编译顺序不一致.
I get the error "Controller 'gssResponseGroup', required by directive 'ngClass', can't be found!" when using the linked Plunker files. Problem is, sometimes it works perfectly fine and other times I get this error. My guess is that the order of loading/compiling of the directives is not consistent.
有人有什么想法吗?
我不明白为什么它说找不到.它在同一个 JavaScript 文件的正上方定义.
I don't see why it states that it can't be found. It is defined right above in the same JavaScript file.
推荐答案
我无法重现您的错误,但我猜您的链接函数中的命令式 transclude()
调用正在引发一场竞赛健康)状况.您在 1.3 中使用了 1.2 之前的转换,因此请查看当前的文档以满足您的转换需求:https://docs.angularjs.org/guide/directive
I can't recreate your error, but I am guessing the imperative transclude()
call in your link function is creating a race condition. You're using pre-1.2 transcludes with 1.3, so take a look at the current docs for your transcluding needs: https://docs.angularjs.org/guide/directive
我也很确定该错误不是指依赖项注入查找失败,而是因为您的子指令中的 require: '^gssResponseGroup',
行找不到- 父指令的 - 尚未实例化/链接的控制器,因为它以一种特别的方式被嵌入.
I'm also pretty sure the error is not referring to a dependency injection lookup failure, but because the require: '^gssResponseGroup',
line in your sub-directive can't find the not-yet-instantiated / linked controller of a parent directive, since it's being transcluded in an ad-hoc way.
这篇关于控制器 <directiveName>,指令 'ngClass' 需要,无法找到的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!