Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Angular Button Color Change with Condition

In my code, I have a list of cells, and I am displaying that list in the form of buttons. On those buttons, you can see the number of elements inside the cell. If a cell is empty, I want it the button to be green and if it has any elements in it, I want it to be red. My code is below, how can I do this?

 <button mat-button class="green fuse-white-fg" 
                            *ngFor="let prm of cell">Package Count: {{prm.PackageCount}}</button>
like image 754
Rocket Monkey Avatar asked Mar 19 '26 13:03

Rocket Monkey


1 Answers

another way to do it as.

<button mat-button [class.green]="!prm.PackageCount" [class.red]="prm.PackageCount" *ngFor="let prm of cell">
  Package Count: {{prm.PackageCount}}
</button>
like image 85
Taimoor Qureshi Avatar answered Mar 22 '26 02:03

Taimoor Qureshi