简体   繁体   中英

Angular change Cell Value Conditionally

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>

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>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM