“Angular [ngclass]” Código de respuesta

ngclass angular

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

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

<some-element [ngClass]="{'first': true, 'second': true, 'third': false}">...</some-element>

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

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

Angular [ngclass]

// class can be added using both the ways
[class.some_class] = "variable === 'value'"
[ngClass]="{'some_class': variable === 'value'}"
// multiple classes 
[ngClass]="{'some_class': variable === 'value', 'some_class_2': variable2 === 'value2'}"
// multiple classes seperated by spcase
[ngClass]="{'some_class some_class_2': variable === 'value'}"
// appropriate class will be applied based on variable value
[ngClass]="{val1 : 'class_1', val2 : 'class_2', val3 : 'class_3'}[variable]"
// ternary operator
[ngClass]="{variable === 'value' ? 'some_class_1' : 'some_class_2'}"
amit.bhagat

Proyecto de clase NG

      
      ngDoCheck()
    
Clever Cockroach

Respuestas similares a “Angular [ngclass]”

Explore las respuestas de código populares por idioma

Explorar otros lenguajes de código