How to use if-else condition with [ngClass] in angular 7?

Akshay Kumar picture Akshay Kumar · Jul 25, 2019 · Viewed 13.8k times · Source

I want to use multiple classes inside Angular [ngClass]. I have two classes, It should work accordingly as per the condition of the flag, that are already passed from the component.ts.

Answer

Tushar picture Tushar · Jul 25, 2019

Do like this:

<div [ngClass]="condition1 ? 'class1' : 'class2' " ></div>

(Ternary Operator Usage)