刚学angular js两天,有一个疑惑,看到angular js中的ng-class指令可以为某一个元素结点添加相应的class。
但是想请问一下,这个跟直接给元素添加class有什么区别吗?angular js最终还是会解析ng-class指令中的内容,然后再给元素添加相应的class。这么做的优势体现在哪呀?就是为了后期方便修改这个元素结点的class吗。
高洛峰2017-05-15 17:07:31
For example: ng-class="{red: By performing operations, you can dynamically add or delete classes, which is much more convenient than using javascript to add or delete classes in the class list
習慣沉默2017-05-15 17:07:31
ngClass is used to dynamically add different classes based on conditions, but native classes do not have this effect
天蓬老师2017-05-15 17:07:31
The value corresponding to the class used in our HTML is a string;
The ng-xxx in angular corresponds to an expression. For example, the ng-class you encountered here corresponds to a key: value.
When value is true, the key style is applied.
For example ng-class="{ someClass : true }";
Note that if your style is some-class, it needs to be expressed as a string type, such as:
ng-class="{ 'some-class' : true }";