How can I change card's colour with "ng-if"?

I want to change my card’s colour in different situations. How can I do that with ng-if?

you shouldn’t be using ng-if for that… but [ngClass] which allows you to dynamically add or remove CSS class using (click).
Learn about [ngClass] of Angular.

I solved my problem with ng-if but thank you so much I will learn! I’m new…

1 Like

Yes, that works too. I realized you can do that with ngIf as well.

 <div *ngIf="false"></div>  never displayed
 <div *ngIf="a > b"></div>   displayed if a is more than b 
 <div *ngIf="str == 'show'"></div>  displayed if str holds the string "show" 
<div *ngIf="function1()"></div>  displayed if myFunc returns a true value 

[ngClass] can add background color as CSS class to any html component too.

or you can use ngStyle to do the same.

Thank you so much. I will try it