【发布时间】:2022-01-17 20:52:34
【问题描述】:
我最初创建了一个静态 HTML 表格,我在其中根据单元格中的值设置公式和 css:
<td *ngIf="r.Num_Of_Days !== 0 "(click)="getCTData(r.Name,'Num_Of_Days','high')" class="rd">
{{r.Num_Of_Days}}
</td>
<td *ngIf="r.Num_Of_Days === 0 "></td>
我不得不改为使用 Angular Material,因为列名是动态的,我必须使用 columnstodisplay 指令来确定要显示的列。我尝试在其中使用 *matCellDef 和 *ngIf 但它引发了错误。我做了一些搜索,发现我需要使用 这可以填充数据,但它不会将函数或 css 应用于单元格。如何正确应用 css 和函数,以便当值为 0 时没有点击事件且单元格不着色,并且如果值大于 0,则应用函数和格式?<td mat-cell *matCellDef="let r">
<ng-container *ngIf="r.Num_Of_Days !== 0;else conditionNotMet"
(click)="getCTData(r.Name,'Num_Of_Days','high')" class="rd">
{{r.Num_Of_Days}}
</ng-container>
</td>
<ng-template #conditionNotMet></ng-template>
【问题讨论】: