我有一个像这样的简单循环:
<div *ngFor="let treatment of data.treatments; let order = index">
{{treatment.order}}
<input type="text" [(ngModel)]="treatment.name.dutch" >
</div>
现在我想在我的模板代码中设置treatment.order = order
。所以列表总是
1 ...
2 ...
3 ...
但是变量treatment.order也将在列表中具有相应的顺序。我似乎找不到办法做到这一点
答案 0 :(得分:1)
创建一个用于对数组进行排序的排序管道
stackoverflow question about sorting pipe
示例:
<div *ngFor="let treatment of data.treatments | sortOrder; let order = index">
{{treatment.order}}
<input type="text" [(ngModel)]="treatment.name.dutch" >
</div>