英文:
Angular change Cell Value Conditionally
问题
我有一个显示这些数据的表格,我想根据单元格的值来更改表格数据,如果单元格的值为1,我想显示勾号,否则显示单元格的值。
你能帮助我吗?
<ng-container matColumnDef="Monday">
<th mat-header-cell *matHeaderCellDef> M </th>
<td mat-cell *matCellDef="let element" [ngClass]="{'make-tick': element.Monday == '1'}"
[ngClass]="{'make-gold': element.Monday == '0'}"> {{ element.Monday}} </td>
</ng-container>
英文:
I have a grid displaying this data, I want to change the table data based upon cell value if cell values are 1 I have to display tick mark else cell value
can you please help me
<ng-container matColumnDef="Monday">
<th mat-header-cell *matHeaderCellDef> M </th>
<td mat-cell *matCellDef="let element" [ngClass]="{'make-tick': element.Monday == '1'}"
[ngClass]="{'make-gold': element.Monday == '0'}"> {{ element.Monday}} </td>
</ng-container>
答案1
得分: 1
你可以使用简单的*ngIf
来实现这个功能。
<ng-container matColumnDef="Monday">
<th mat-header-cell *matHeaderCellDef> M </th>
<td mat-cell *matCellDef="let element" [ngClass]="{'make-tick': element.Monday == '1', 'make-gold': element.Monday == '0'}">
<ng-container *ngIf="element.Monday != '1'; else tick">
{{element.Monday}}
</ng-container>
<ng-template #tick><!-- 打勾的标记 --></ng-template>
</td>
</ng-container>
英文:
You can use a simple *ngIf
to do that.
<ng-container matColumnDef="Monday">
<th mat-header-cell *matHeaderCellDef> M </th>
<td mat-cell *matCellDef="let element"
[ngClass]="{'make-tick': element.Monday == '1', 'make-gold': element.Monday == '0'}">
<ng-container *ngIf="element.Monday != '1'; else tick">
{{element.Monday}}
</ng-container>
<ng-template #tick><!-- markup for tick --></ng-template>
</td>
</ng-container>
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论