使用 ngif 在 mat-table 中隐藏一行

Ton*_*ony 9 angular mat-table

单击 mat-table 中的按钮后,我试图隐藏一行。我不知道该放在哪里*ngIf。我试过了,ng-container但它不起作用。下面是我的 HTML 文件。

<mat-table class="lessons-table mat-elevation-z8" [dataSource]="application">
  <ng-container matColumnDef="ID">
    <mat-header-cell *matHeaderCellDef>ID</mat-header-cell>
    <mat-cell *matCellDef="let application">{{application.id}}</mat-cell>
  </ng-container>

  <ng-container matColumnDef="Name">
    <mat-header-cell *matHeaderCellDef>Name</mat-header-cell>
    <mat-cell *matCellDef="let application">{{application.name}}</mat-cell>
  </ng-container>

  <ng-container matColumnDef="ApplicationDate">
    <mat-header-cell *matHeaderCellDef>Application Date</mat-header-cell>
    <mat-cell *matCellDef="let application">{{application.applyDate}}</mat-cell>
  </ng-container>

  <ng-container matColumnDef="TrackingNumber">
    <mat-header-cell *matHeaderCellDef>Tracking Number</mat-header-cell>
    <mat-cell *matCellDef="let application">{{application.trackNumber}}</mat-cell>
  </ng-container>

  <ng-container matColumnDef="Operation">
    <mat-header-cell *matHeaderCellDef>Operation</mat-header-cell>
    <mat-cell *matCellDef="let application">
      <button mat-raised-button color="primary" (click)="onClickGrant()">Grant</button>&nbsp; &nbsp; &nbsp;
      <button mat-raised-button color="warn" (click)="onClickDeny()">Deny</button>
    </mat-cell>
  </ng-container>

  <mat-header-row *matHeaderRowDef="displayedColumns"></mat-header-row>
  <mat-row *matRowDef="let row; columns: displayedColumns"></mat-row>
</mat-table>
<mat-paginator [pageSizeOptions]="[5,10,15,20]" [pageSize]="5" showFirstLastButtons></mat-paginator>
Run Code Online (Sandbox Code Playgroud)

Pat*_*ski 9

另一种方法是添加类mat-row并使用 CSS 隐藏它。

<mat-row *matRowDef="..." [class.hidden]="YOUR_IF_HERE"></mat-row>
Run Code Online (Sandbox Code Playgroud)

您还可以查看来自 Angualr Material 站点的类似示例:https ://stackblitz.com/angular/voqbanbobpa?file = app%2Ftable-expandable-rows-example.ts