angularjs : setting class attribute in a directive template

余生长醉 提交于 2019-12-11 05:30:32

问题


I'm trying to set the class attribute of my directive. That's how I do it:

the relevant code in the directive

template: '<input class="myClass" />'

scope:{
 myClass = '@'
}

and that's how I call it

<my-directive my-class="someClass" />

Unfortunately, nothing happens. No errors, but the class is just not set.

Anything I'm missing ?


回答1:


myClass is a scope variable in your new isolated scope. You have to write template: '<input class="{{myClass}}" /> or template: '<input ng-class="myClass" />



来源:https://stackoverflow.com/questions/16198995/angularjs-setting-class-attribute-in-a-directive-template

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!