angularjs:在指令模板设置类属性 [英] angularjs : setting class attribute in a directive template
本文介绍了angularjs:在指令模板设置类属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想设置我的指令的class属性。这就是我如何做到这一点:
I'm trying to set the class attribute of my directive. That's how I do it:
相关code在指令
template: '<input class="myClass" />'
scope:{
myClass = '@'
}
和这就是我把它叫做
<my-directive my-class="someClass" />
不幸的是,没有任何反应。没有错误,但是类是不设置。
Unfortunately, nothing happens. No errors, but the class is just not set.
什么我失踪?
推荐答案
MyClass的是在新的孤立范围的范围变量。你必须写模板:'&LT;输入类={{MyClass的}}/&GT;
或模板:'&LT;输入NG-类=MyClass的/&GT;
myClass is a scope variable in your new isolated scope. You have to write template: '<input class="{{myClass}}" />
or template: '<input ng-class="myClass" />
这篇关于angularjs:在指令模板设置类属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文