1//Type one
2[class.my_class] = "step === 'step1'"
3
4//Type two
5[ngClass]="{'my_class': step === 'step1'}"
6and multiple option:
7[ngClass]="{'my_class': step === 'step1', 'my_class2' : step === 'step2' }"
8
9//Type three
10[ngClass]="{1 : 'my_class1', 2 : 'my_class2', 3 : 'my_class4'}[step]"
11
12//Type four
13[ngClass]="step == 'step1' ? 'my_class1' : 'my_class2'"
1<div [ngStyle]="{'background-color':person.country === 'UK' ? 'green' : 'red' }"></<div>
1[ngClass]="{'my_class': step === 'step1', 'my_class2' : step === 'step2' }"
2
1
2 content_copy
3
4 <some-element [ngClass]="'first second'">...</some-element>
5
6<some-element [ngClass]="['first', 'second']">...</some-element>
7
8<some-element [ngClass]="{'first': true, 'second': true, 'third': false}">...</some-element>
9
10<some-element [ngClass]="stringExp|arrayExp|objExp">...</some-element>
11
12<some-element [ngClass]="{'class1 class2 class3' : true}">...</some-element>
13
1<div [ngClass]="{
2'green': number > 5,
3 'red': number <= 5,
4}" ></div>
5//if the number is over 5, the class 'green' will be added to the div.
6//if the number is below or equal 5, the class 'red' will be added to the div.