files
是对象数组。它始终具有 name 属性,但可能具有也可能不具有 Progress 属性。进度具有数字类型的值。有没有办法检查 ngIf
中是否存在进度:-
<tr *ngFor="let file of files; let i=index;">
<td>{{file.name}}</td>
<td *ngIf="file.progress"> Show This if progress doesnt exist</td>
<td *ngIf="file.progress"> Show This if progress exists</td>
<tr>
最佳答案
你可以这样尝试。您可以使用 <ng-template>
并实现 else 条件。所以不需要执行两次*ngIf
。
<tr *ngFor="let file of files; let i=index;">
<td>{{file.name}}</td>
<td *ngIf="file?.progress; else elsePart"> Show This if progress doesnt exist</td>
<ng-template #elsePart>
<td> Show This if progress exists</td>
</ng-template>
<tr>
关于angular - 在 ngIf 中如何检查数组键是否存在?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56078118/