相关疑难解决方法(0)

如何在 Angular 4 的 HTML 中包含或排除属性

我正在使用带有角度材料的 angular 4 来构建一张桌子。我希望在mat-sort-header以下模板上有条件地添加。

<mat-header-cell *matHeaderCellDef mat-sort-header>Id</mat-header-cell>
Run Code Online (Sandbox Code Playgroud)

我尝试了以下代码:

<mat-header-cell *matHeaderCellDef [mat-sort-header]=" column!='id' ? column : false ">Id</mat-header-cell>
Run Code Online (Sandbox Code Playgroud)

但它仍然在该列的表中添加排序标题。

我的整个表格如下所示,并且工作正常,除了排序标题问题:

  <mat-table #table1 [dataSource]="records" matSort class="mat-cell">

    <ng-container *ngFor="let column of keys" [matColumnDef]="column">
      <mat-header-cell *matHeaderCellDef [mat-sort-header]=" column!='actions' ? column : false ">
        <p *ngIf=" column!='actions' ">{{ column }}</p>
        <button *ngIf=" column=='actions' " mat-icon-button color="primary" (click)="functionA()">
          <mat-icon class="indigo-icon" aria-label="Example icon-button with a heart icon">add</mat-icon>
        </button>

      </mat-header-cell>
      <mat-cell *matCellDef="let row; let i=index;">
        <p *ngIf=" column!='actions' ">{{ row[column] }}</p>
        <button *ngIf=" column=='actions' " mat-icon-button …
Run Code Online (Sandbox Code Playgroud)

angular-material angular-material2 angular

7
推荐指数
2
解决办法
5500
查看次数