![](/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.