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:
指令中的相关代码
template: '<input class="myClass" />'
scope:{
myClass = '@'
}
我就是这么称呼它的
<my-directive my-class="someClass" />
不幸的是,没有任何反应.没有错误,只是没有设置类.
Unfortunately, nothing happens. No errors, but the class is just not set.
有什么我遗漏的吗?
推荐答案
myClass 是新的隔离作用域中的作用域变量.您必须编写 template: '<input class="{{myClass}}"/>
或 template: '<input ng-class="myClass"/>代码>
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屋!
查看全文