angular.js - angular的ng-class指令和class有什么区别
曾经蜡笔没有小新
曾经蜡笔没有小新 2017-05-15 17:05:31
0
4
643

刚学angular js两天,有一个疑惑,看到angular js中的ng-class指令可以为某一个元素结点添加相应的class。

但是想请问一下,这个跟直接给元素添加class有什么区别吗?angular js最终还是会解析ng-class指令中的内容,然后再给元素添加相应的class。这么做的优势体现在哪呀?就是为了后期方便修改这个元素结点的class吗。

曾经蜡笔没有小新
曾经蜡笔没有小新

reply all(4)
小葫芦

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

習慣沉默

ngClass is used to dynamically add different classes based on conditions, but native classes do not have this effect

迷茫

ng-class is a command that allows you to change the class based on logic

Peter_Zhu

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 }";

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template