Добавить условие для значения строки (угловой материал) - PullRequest
0 голосов
/ 03 мая 2019

Я хочу добавить условие к значению текущего столбца. Я не могу прочитать значение текущей строки. я не знаю, какую переменную я должен использовать для проверки условия, в котором я использовал строку, но он не определен

<ng-container matColumnDef="idCve">
    <th mat-header-cell matHeaderCellDef mat-sort-header> IDCVE </th>
    <ng-container ngIf="row.idCve != null; else dothis" >
        <td mat-cell matCellDef="let row"> {{row.idCve}} </td>
    </ng-container>
    <ng-template #dothid>
        <td mat-cell matCellDef="let row"> --------- </td>
    </ng-template>
</ng-container>

Файл TS

Constructor(vulnerabilityServiceService: VulnerabilityServiceService) {
    const vulnerabilities = vulnerabilityServiceService.getVulnerabilities();
    // Assign the data to the data source for the table to render
    this.dataSource = new MatTableDataSource(vulnerabilities);
}

1 Ответ

0 голосов
/ 03 мая 2019

Может, так? :)

HTML

<table mat-table [dataSource]="dataSource" class="mat-elevation-z8">
<ng-container matColumnDef="position">
    <th mat-header-cell *matHeaderCellDef> No. </th>
    <td mat-cell *matCellDef="let element">
        <div *ngIf="element != 0; else elseDiv">
            {{element}}
        </div>
        <ng-template #elseDiv>
            ----------------
        </ng-template>
    </td>
</ng-container>
<tr mat-header-row *matHeaderRowDef="displayedColumns"></tr>
<tr mat-row *matRowDef="let row; columns: displayedColumns;"></tr>

TS

  displayedColumns: string[] = ['position'];
  dataSource = [1, 0, 2, 0, 3, 0];
...