export directive NgClass
export directive NgClass
exported from angular2/common defined in angular2/src/common/directives/ng_class.ts (line 13)
The NgClass
directive conditionally adds and removes CSS classes on an HTML element based on
an expression's evaluation result.
The result of an expression evaluation is interpreted differently depending on type of the expression evaluation result:
string
- all the CSS classes listed in a string (space delimited) are addedArray
- all the CSS classes (Array elements) are addedObject
- each key corresponds to a CSS class name while values are interpreted as expressions evaluating toBoolean
. If a given expression evaluates totrue
a corresponding CSS class is added - otherwise it is removed.
While the NgClass
directive can interpret expressions evaluating to string
, Array
or Object
, the Object
-based version is the most often used and has an advantage of keeping
all the CSS class names in a template.
Example (live demo):
Selectors
[ngClass]
Inputs
ng-class
bound to NgClass.rawClass
class
bound to NgClass.initialClasses
Constructor
constructor(_iterableDiffers: IterableDiffers, _keyValueDiffers: KeyValueDiffers, _ngEl: ElementRef, _renderer: Renderer)
constructor(_iterableDiffers: IterableDiffers, _keyValueDiffers: KeyValueDiffers, _ngEl: ElementRef, _renderer: Renderer)
Not Yet Documented
Members
initialClasses
initialClasses
Not Yet Documented
rawClass
rawClass
Not Yet Documented
ngDoCheck() : void
ngDoCheck() : void
Not Yet Documented
ngOnDestroy() : void
ngOnDestroy() : void
Not Yet Documented