AngularJS 指令链接函数未被调用 [英] AngularJS directive link function not being called
问题描述
我正在尝试将 angular-http-auth 库与引导模式窗口一起使用.模态工作正常,但我对指令有问题.这是一个 jsfiddle 链接 - http://jsfiddle.net/jCUSh/85/ .我正在尝试添加一个将被调用并添加侦听器的指令.我已经简化了 jsfiddle 中的示例,因此您不会看到 http-auth 导入.但是 scope.on('') 元素仍然存在(无论如何它们都不会破坏图片).
I am trying to use angular-http-auth library with bootstrap modal window. Modals are working fine but I have problems with directives. Here is a jsfiddle link - http://jsfiddle.net/jCUSh/85/ . I am trying to add a directive that will be invoked and that adds listeners. I have simplified the example in jsfiddle, so you won't see http-auth imports. However scope.on('') elements are still left (they don't break the picture anyway).
我的问题是 - 为什么不调用链接函数?我添加了 elem.addClass('test')
作为示例.我相信解决方案超级简单,就是看不到.
My question is - why isn't the linking function called? I added elem.addClass('test')
as an example.
I believe the solution is super simple, just unable to see it.
还有一个不太重要的问题 - 可以将作用域作为参数传递给另一个作用域吗?我需要它来关闭模态窗口.
Also less important question - is it ok to pass scope as a parameter to another scope? I need it to close the modal window.
谢谢
推荐答案
这里有两件事情在起作用..
Two things are at play here..
一个是你必须通过 class
属性而不是 ng-class
One is you must pass the directive through the class
attribute and not the ng-class
其次,您传递给限制属性的 "C"
字符是一个 ASCII 为 1057 的字符(不是我们通常的 ASCII 67 字符)
Secondly, the "C"
character you pass to the restrict property is a character with ASCII of 1057 (not our usual ASCII 67 char)
固定演示在 http://jsfiddle.net/gaby/jCUSh/87/
这篇关于AngularJS 指令链接函数未被调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!