add class in angular code example

Example 1: ngclass multiple conditions

<a [ngClass]="{'class1':array.status === 'active','class2':array.status === 'idle','class3':array.status === 'inactive',}">

Example 2: angular 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>

Example 3: angualr add class to component

@Component({
   selector: 'app-your-component',
   templateUrl: './your-component.component.html',,
   host: {'class': 'your-class'}
})
export class YourComponent implements OnInit {
...
}

Example 4: add class to element angular in ts

type one

[class.my-class]="step === 'step1'"
type two

[ngClass]="{'my-class': step === 'step1'}"
and multiple option:

[ngClass]="{'my-class': step === 'step1', 'my-class2':step === 'step2' }"
type three

[ngClass]="{1:'my-class1',2:'my-class2',3:'my-class4'}[step]"
type four

[ngClass]="(step=='step1')?'my-class1':'my-class2'"

Example 5: Angular 8 ngClass If

[class.my-class]="step=='step1'"

Example 6: ng class project

ngDoCheck()