![](/img/trans.png)
[英]How to iterate object which contains array in one field in angular
[英]angular 2 - how do I iterate through a JSON response that contains an object which contains an array of objects?
我正在使用我的朋友创建的Web API,这是示例响应:
{
types: [
{
id: 1,
contents: [
{
id: 1001,
perishable: 0
},
{
id: 1002,
perishable: 0
}
]
}
]
}
因此,如果返回的响应中包含3种类型的内容,而每种类型都包含3种内容,那么在下面的这种情况下,如何使用转发器? 我可以正确获取类型ID,但是在重复内容时遇到了麻烦。
<div *ngFor="let type of response.types">
<h2>{{type.id}}</h2>
<!-- here I want to show basically divs for each of the objects in contents -->
<div *ngFor="what should I do here?">
<p>{{content.id}}</p>
<p>{{content.perishable}}</p>
</div>
</div>
<div *ngFor="let type of response.types">
<h2>{{type.id}}</h2>
<div *ngFor="let content of type.contents">
<p>{{content.id}}</p>
<p>{{content.perishable}}</p>
</div>
</div>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.