Latest web development tutorials

AngularJS ng-class instruction

AngularJS Reference Manual AngularJS Reference Manual


AngularJS examples

Modify <div> element categories:

<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 instruction is used to dynamically bind HTML elements of one or more CSS classes.

ng-class values of instruction can be a string, an object, or an array.

If a string, a plurality of class names separated by spaces.

If the object, you need to use key-value pairs, the class name for the key you want to add, value is a Boolean value. Only in value will be added to true class.

If it is an array, or may be composed of a combination of string objects, elements of the array can be strings or objects.


grammar

<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 AngularJS Reference Manual