【发布时间】:2021-11-04 09:02:18
【问题描述】:
我在mat-cell中放了一个按钮,其实一个图标也可以,因为我的目的是指示表格中每条记录的颜色属性。每条记录都有自己的颜色值:名称、十六进制代码和前景,例如,'Red',值:'#ff1744',前景:'white'。
<ng-container matColumnDef="sku">
<mat-header-cell *matHeaderCellDef mat-sort-header>SKU</mat-header-cell>
<mat-cell *matCellDef="let element">{{element.sku}}</mat-cell>
</ng-container>
<ng-container matColumnDef="color">
<mat-header-cell *matHeaderCellDef mat-sort-header> Color </mat-header-cell>
<mat-cell *matCellDef="let element">
<button [disabled]="true"
[style.background-color]="element.value"
[style.color]="element.foreground"
class="color-preview">
</button>
</mat-cell>
</ng-container>
<ng-container matColumnDef="pictureUrl">......
要给按钮一个圆形,请在 css 中设置它,如下所示。这确实符合预期。
.color-preview {
width: 20px;
height: 20px;
border-radius: 50%;
}
通过上述方法,我似乎无法获得所需颜色的按钮,例如十六进制值为#ff1744 的红色按钮。任何人都可以帮忙吗?任何更正或解决方案将不胜感激。
【问题讨论】:
标签: html css angular colors angular-material