角材料表基于[dataSource]的Apply类

时间:2020-09-01 07:58:08

标签: angular angular-material angular-ng-class

我已经建立了一个角材料表,如果[dataSource]返回isActive = false,我想使用类error-text

我正在努力做到这一点:

<table
  mat-table
  [dataSource]="dataSource"
  matSort
  class="mat-elevation-z8 table table-striped"
  [ngClass]="dataSource?.isactive == 'false' ? 'error-text' :''"
>

我的课程不适用于表格。

我知道我可以将此类应用于表的每一行,但这对我来说似乎是不正确的解决方案:

<ng-container matColumnDef="fullname">
    <th mat-header-cell *matHeaderCellDef mat-sort-header>
      {{ translate("name") }}
    </th>
    <td
      mat-cell
      *matCellDef="let element"
      [ngClass]="element?.isactive == 'false' ? 'error-text' :''"
    >
      {{ element.fullname }}
    </td>
  </ng-container>

有没有人找到一种解决方案,我可以只声明一次ngClass并将其应用于整个表?

0 个答案:

没有答案