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>
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>
Share
Improve this question
asked May 6, 2021 at 6:49
Rocket MonkeyRocket Monkey
3901 gold badge7 silver badges24 bronze badges
3 Answers
Reset to default 3another 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>
You can use ngStyle
attribute:
<button mat-button [ngStyle]="{ 'background-color': prm.PackageCount ? 'green' : 'red' }" *ngFor="let prm of cell">
Package Count: {{prm.PackageCount}}
</button>
You can use ngclass
.
<button mat-button class="fuse-white-fg"
[ngClass] = "{'green':!prm.PackageCount, 'red':prm.PackageCount>0}"
*ngFor="let prm of cell">Package Count: {{prm.PackageCount}}</button>
where green
and red
are css classes
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744310124a4567905.html
评论列表(0条)