Home:ALL Converter>Angular Material Table Apply Class based on [dataSource]

Angular Material Table Apply Class based on [dataSource]

Ask Time:2020-09-01T15:58:08         Author:Janey

Json Formatter

I have built an Angular Material Table and would like to use class error-text if the [dataSource] returns isActive=false.

I'm trying to do this with no luck:

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

My class isn't applied to the table.

I understand that I can apply this class to each row of my table, but this seems like the incorrect solution to me:

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

Has anyone found a solution where I can simply state the ngClass once and it is applied to the whole table?

Author:Janey,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/63683579/angular-material-table-apply-class-based-on-datasource