Angular показывает только элементы массива, которые относятся к определенному условию с * ngIf? - PullRequest
0 голосов
/ 24 января 2019

Я использую таблицу материалов для отображения моего массива.Мне нужна опция для пользователя, поэтому, когда он помечает «ежедневно», он показывает только те файлы, в которых 5-й последний символ file_name равен «D», а «M» для месячных.

<div style="overflow-x:auto;">
  <table mat-table [dataSource]="dataSource" matSort class="mat-elevation-z8">

    <!-- Unit Column -->
    <ng-container matColumnDef="unit">
      <th mat-header-cell *matHeaderCellDef>Unit</th>
      <td mat-cell *matCellDef="let element"  *ngIf=" file_name.charAt(((apiDataFile.file_name).length) - 5) == 'M'"> {{element.unit}} </td>
    </ng-container>

    <!-- File Name Column -->
    <ng-container matColumnDef="file_name">
      <th mat-header-cell *matHeaderCellDef> File Name</th>
      <td mat-cell *matCellDef="let element" *ngIf=" file_name.charAt(((apiDataFile.file_name).length) - 5) == 'M'"> {{element.file_name}} </td>
    </ng-container>


    <tr mat-header-row *matHeaderRowDef="displayedColumns; sticky: true"></tr>
    <tr mat-row *matRowDef="let row; columns: displayedColumns;"
        [ngClass]="{highlighted: selectedRowIndex == row.id}"  (click)="highlight(row)" >
    </tr>
  </table>
  <mat-paginator [pageSizeOptions]="[20, 5, 10, 50, 100]" showFirstLastButtons></mat-paginator>

</div>

В моем примере я хочу печатать только месячные файлы, что означает, что 5-й символ в конце равен «M», без опции галочки.Как мне этого добиться?

...