Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add multiple classes to a condition in angular

Tags:

angular

I have this code

    <div *ngFor="let d of getDays(); let i = index" class="day hr left" (click)="pick(d, h)" [class.white]="days[d].indexOf(h) > -1">
</div>

It works fine but my question is how do I add another class name in this part [class.white]="days[d].indexOf(h) > -1"? I have another class called .redborder{border 1px solid red}. I tried this but didn't work [class.white.redborder]="days[d].indexOf(h) > -1". What else am I supposed to do?

like image 660
Wafula Samuel Avatar asked Mar 10 '23 07:03

Wafula Samuel


1 Answers

You can use the ngClass directive:

<element [ngClass]="{'white redborder' : days[d].indexOf(h) > -1}"></element>

For elseif I guess you can use this:

<element [ngClass]="days[d].indexOf(h) > -1 ? 'white' : 'redborder'"></element>
like image 163
Poul Kruijt Avatar answered Apr 02 '23 01:04

Poul Kruijt