I just learned angular js for two days and I have a doubt. I saw that the ng-class directive in angular js can add a corresponding class to a certain element node.
But I would like to ask, is there any difference between this and adding a class directly to an element? Angular js will eventually parse the content in the ng-class directive and then add the corresponding class to the element. What are the advantages of doing this? Is it just for the convenience of modifying the class of this element node later?
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
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 }";