问题
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