【发布时间】:2019-09-27 15:56:34
【问题描述】:
我有两个数组文件,当前正在运行。
假设文件在索引 0 中,它的进度在 currentlyRunning[1].progress 内,即索引 1
我正在运行ngFor 来显示所有文件。 td 中的 ngIf 是否可以获取正确的进度,因为索引可能不同但文件 ID 是唯一的。
<tr *ngFor="let files of File; let index=i;">
<td>
{{file.name}}
</td>
<td>
{{file.id}}
</td>
<td *ngIf="file.id === currentlyRunning[i].id">
{{currentlyRunning.progress}}
</td>
<tr>
【问题讨论】:
-
最好创建一个字典/索引器并以这种方式检索它。这将更具可读性和性能。
-
另见Declare and initialize a Dictionary in Typescript,
currentlyRunning将是查找。
标签: angular