【问题标题】:Add condition for row value (angular material)为行值添加条件(角度材料)
【发布时间】:2019-09-21 19:33:35
【问题描述】:

我想在当前列的值上添加一个条件。我无法读取当前行的值。 我不知道我必须使用什么变量来检查我使用行但未定义的条件

<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);
}

【问题讨论】:

  • 漏洞服务服务.getVulnerabilities()从哪里获取漏洞?
  • 您好achraf,您是否看到模板的字母ID 错误? &lt;ng-template #dothid&gt;,这是示例还是真实代码?

标签: html angular typescript angular-material mat-table


【解决方案1】:

也许是这样的? :)

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];

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-03-23
    • 1970-01-01
    • 2019-02-11
    • 2015-12-10
    • 1970-01-01
    • 2017-12-08
    • 2016-03-16
    • 2019-11-05
    相关资源
    最近更新 更多