如何在所有对象的数组中显示特定字段

时间:2019-01-17 12:13:44

标签: angular

我正在这样进入控制台:

article:Array
0:Object
articleId: "WMCA880211"
competingInterests: "ff"
content: Array(3)
0: {title: "Abstract", content: "fdd", illustrations: Array(1)}
1: {title: "Introduction", content: "jj", illustrations: Array(1)}
2: {title: "Models", content: "kk", illustrations: Array(1)}

我要在内容数组中显示所有对象的标题。

我尝试过这样,在这里我使用两种方式进行数据绑定:

<div *ngFor="let article of latestarticles">
<div class="row" *ngFor="let Content of article.content">
<input class="form-control" id="usr" name="content" [(ngModel)]="Content.title">
</div>
</div>

我只输出“ Models”。我的意思是内容数组只有最后一个对象。 如何获取内容数组中所有“ title”的对象?

1 个答案:

答案 0 :(得分:0)

name属性应该是唯一的。

尝试一下:

<div *ngFor="let article of latestarticles">
 <div class="row" *ngFor="let Content of article.content; let i = index">
  <input class="form-control" id="usr" [name]="'content_'+i" [(ngModel)]="Content.title">
 </div>
</div>