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


#1

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


#2

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.


#3

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


#4

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.


#5

Thank you so much. I will try it