“Kątowy [ngclass]” Kod odpowiedzi

kątowa ngclass

      
        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

Kątowy [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

Projekt klasy NG

      
      ngDoCheck()
    
Clever Cockroach

Odpowiedzi podobne do “Kątowy [ngclass]”

Przeglądaj popularne odpowiedzi na kod według języka

Przeglądaj inne języki kodu