Как использовать Angular CurrencyPipe в столбце Материал? - PullRequest
1 голос
/ 23 октября 2019

Как использовать Angular CurrencyPipe в столбце Материал. Все мои столбцы являются динамическими и представлены в tableView.columns

Мой шаблон

<ng-container [matColumnDef]="col" *ngFor="let col of tableView.columns;let i=index">
  <mat-header-cell *matHeaderCellDef>{{col}}</mat-header-cell>
  <mat-cell [class]="tRow.cells[i].classes" *matCellDef="let tRow">{{ tRow.cells[i].text }}</mat-cell>
  <mat-footer-cell *matFooterCellDef>{{ tableView.footer.cells[i].text }}</mat-footer-cell>
</ng-container>

В моем последнем столбце я хочу добавить | currency

Ответы [ 2 ]

2 голосов
/ 23 октября 2019

Извините, я не читал, что вы хотели передать последний столбец.

Вы можете использовать последнюю переменную на вашем ngFor. Чтобы увидеть, если это последний столбец.

<ng-container [matColumnDef]="col" *ngFor="let col of tableView.columns;let i=index; let last=last;">
    <mat-header-cell *matHeaderCellDef>{{col}}</mat-header-cell>
    <mat-cell [class]="tRow.cells[i].classes" *matCellDef="let tRow">
      <span *ngIf="last">
        {{ tRow.cells[i].text | currency}}
      </span>
      <span *ngIf="!last">
          {{ tRow.cells[i].text}}
        </span>
    </mat-cell>
    <mat-footer-cell *matFooterCellDef>{{ tableView.footer.cells[i].text }}</mat-footer-cell>
</ng-container>
0 голосов
/ 23 октября 2019

Попробуйте это

     <ng-container [matColumnDef]="col" *ngFor="let col of tableView.columns;let i=index;let last=last">
            <mat-header-cell *matHeaderCellDef>{{col}}</mat-header-cell>
            <mat-cell  [class]="tRow.cells[i].classes" *matCellDef="let tRow">
             <span *ngIf="!last">{{ tRow.cells[i].text }}</span>
             <span *ngIf="last">{{ tRow.cells[i].text |currency}}</span>
            </mat-cell>       
            <mat-footer-cell *matFooterCellDef>{{ tableView.footer.cells[i].text}}</mat-footer-cell>      
     </ng-container>
...