GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Docs
  • Tutorials
  • Playground
  • Reference
  • code
  • Class bindings
  • NgClass

This view

  • Original page
  • New address

GeezerVison is showing angular.dev — NgClass • Angular

API

    
      class NgClass implements DoCheck {}
    
    
@param_ngElElementRef<any>
@param_rendererRenderer2
@returnsNgClass
@returnsvoid

Description

Adds and removes CSS classes on an HTML element.

The CSS classes are updated as follows, depending on the type of the expression evaluation:

  • string - the CSS classes listed in the string (space delimited) are added,
  • Array - the CSS classes declared as Array elements are added,
  • Object - keys are CSS classes that get added when the expression given in the value evaluates to a truthy value, otherwise they are removed.

Exported by

  • CommonModule

Usage Notes

<some-element [ngClass]="stringExp|arrayExp|objExp|Set">...</some-element>

<some-element [ngClass]="{'class1 class2 class3' : true}">...</some-element>

For more simple use cases you can use the class bindings directly. It doesn't require importing a directive.

<some-element [class]="'first second'">...</some-element>

<some-element [class.expanded]="isExpanded">...</some-element>

<some-element [class]="['first', 'second']">...</some-element>

<some-element [class]="{'first': true, 'second': true, 'third': false}">...</some-element>
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.