我在我的项目中使用 Angular 2,并且我有这个 json 对象:
[
{
"city": "toto"
},
{
"city": "titi"
},
{
"city": "tata"
},
...
]
我想要的是,像这样在 UI 中填充这个对象:
toto -> titi (with a button here)
titi -> tata (with a button here)
我尝试了这个,但它不起作用:
<div formArrayName="prices">
<div *ngFor="let myGroup of myForm.controls.prices.controls; let i=index">
<div [formGroupName]="i">
<span *ngIf="myForm.controls.prices.controls.length > 1" >
</span>
<div class="input-group spinner">
<input type="text" formControlName="price" class="form-control" >
</div>
</div>
请问有什么建议吗?
最佳答案
类似这样的吗?
<div *ngFor="let item of items; let i=index">
<span>{{item.city}}</span> --> <span *ngIf="items[i+1]">{{items[i+1].city}}</span>
</div>
输出:
toto --> titi
titi --> tata
tata -->
如果您不想显示最后一项,请使用 let last = last
并过滤掉最后一项。
<div *ngFor="let item of items; let i=index; let last = last">
<div *ngIf="!last">
<span>{{item.city}}</span> --> <span *ngIf="items[i+1]">{{items[i+1].city}}</span>
</div>
</div>
关于javascript - 如何在 UI Angular 2 中填充 json 对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46471200/