How can we write two ngClass in one div?

528 Views Asked by At

Can we add two ng-class in one div? If so then how to write it. How can we write this together?

Thank you in advance.

<div [ngClass]={'white-background': policy number.length <=0}
[ngClass]="getSomeClass()"> 
2

There are 2 best solutions below

2
On BEST ANSWER

You can do this

<div [ngClass]="{'class1': getClass1(), 'class2': getClass2()}">
</div>

With getClass1() and getClass2() returning true or false to conditionally apply class1, class2.

0
On

This worked for me

[ngClass]=['getSomeClass()', policyNumber.length<=0 ? 'white-background' : '']