gpt4 book ai didi

html - 为行值添加条件( Angular Material )

转载 作者:行者123 更新时间:2023-12-01 01:48:42 25 4
gpt4 key购买 nike

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

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

最佳答案

也许是这样的? :)

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

关于html - 为行值添加条件( Angular Material ),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55966668/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com