AngularJS ng-class Instruction
AngularJS Examples
Modify
<
select
ng-model=
"home"
<
option
value=
"sky"
Sky
<
/option
<
option
value=
"tomato"
Tomato
<
/option
<
/select
<
div
ng-class=
"home"
<
h1
Welcome Home!
<
/h1
<
p
I like it!
<
/p
<
/div
Try it »
Definition and Usage
ng-class The directive dynamically binds one or more CSS classes to HTML elements.
ng-class The value of the directive can be a string, an object, or an array.
If it is a string, multiple class names are separated by spaces.
If it is an object, use key-value pairs, where the key is the class name you want to add and the value is a boolean. The class is only added when the value is true.
If it is an array, it can be composed of a combination of strings or objects; the elements of the array can be strings or objects.
Syntax
<
element
ng-class=
"expression"
<
/element
All HTML elements are supported.
Parameter value
| Value | Description |
|---|---|
| expression | An expression that returns one or more class names. |
AngularJS Reference Manual