Wafula Samuel
Wafula Samuel

Reputation: 540

How to add multiple classes to a condition in 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?

Upvotes: 4

Views: 2767

Answers (1)

Poul Kruijt
Poul Kruijt

Reputation: 71921

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>

Upvotes: 7

Related Questions