ngClass
ng
The ngClass
directive allows you to dynamically set CSS classes on an HTML element by databinding
an expression that represents all classes to be added.
The directive won't add duplicate classes if a particular class was already set.
When the expression changes, the previously added classes are removed and only then the new classes are added.
<ANY ng-class="{expression}"> ... </ANY>as class
<ANY class="ng-class: {expression};"> ... </ANY>
Param | Type | Details |
---|---|---|
ngClass | expression | Expression to eval. The result of the evaluation can be a string representing space delimited class names, an array, or a map of class names to boolean values. In the case of a map, the names of the properties whose values are truthy will be added as css classes to the element. |
Example that demonstrates basic bindings via ngClass directive.
The example below demonstrates how to perform animations using ngClass.
The ngClass directive still supports CSS3 Transitions/Animations even if they do not follow the ngAnimate CSS naming structure. Upon animation ngAnimate will apply supplementary CSS classes to track the start and end of an animation, but this will not hinder any pre-existing CSS transitions already on the element. To get an idea of what happens during a class-based animation, be sure to view the step by step details of $animate.addClass and $animate.removeClass.