[英]ngFor iterating through inside array object array using angular 7
I have this JSON我有这个 JSON
[ [
{
Id: "14",
Title: "HR Europe",
Description: "HR Europe",
Color: "3B23FF",
Contents: [
{
Id: "15",
Title: "W.I.D.E Experience",
Description: "Discover our Value!",
Date: new Date('2019-12-02'),
Type: "content",
},
{
Id: "17",
Title: Experience",
Description: "Discover our Value!",
Date: new Date('2019-12-02'),
Type: "content",
}
]
},
{
Id: "12",
Title: "Company",
Description: "Company",
Color: "4FFF26",
Contents: [
{
Id: "13",
Title: "CEO & Presidents Environmental Message",
Description: "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
Date: new Date('2020-02-13'),
Type: "content",
}
]
},
{
Id: "8",
Title: "Engine",
Description: "Engine",
Color: "FF4F0C",
Contents: [
{
Id: "10",
Title: "Pre Bunker Training",
Description: "yyyyyyyyyyyyyyyyyyyyyyyyyyyyy",
Date: new Date('2019-12-02'),
Type: "content",
},
{
Id: "11",
Title: "Exhaust Gas Cleaning System pH-Sensor cleaning",
Description: "uuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuu",
Date: new Date('2019-12-02'),
Type: "content",
}
]
I want to show this title Title: "CEO & Presidents Environmental Message"
{{item?.Contents.Title}}
but I used not correct and show我想显示此标题
Title: "CEO & Presidents Environmental Message"
{{item?.Contents.Title}}
但我使用不正确并显示
Cannot find a differ supporting object '[object Object]' of type 'object'.
找不到不同的支持 object '[object Object]' 类型为 'object'。 NgFor only supports binding to Iterables such as Arrays.
NgFor 仅支持绑定到 Iterables,例如 Arrays。
Can you share with me any idea how to use *ngFor
in this part?你能和我分享一下如何在这部分使用
*ngFor
吗?
I've created an example of what you're asking, basically it uses two *ngFor to go through the data.我已经创建了一个您所要求的示例,基本上它通过数据使用两个 *ngFor 到 go。
You need a first ngFor to iterate the array of items you provided.您需要第一个 ngFor 来迭代您提供的项目数组。
Then a second ngFor to iterate the array of Contents for each item iterated above.然后第二个 ngFor 为上面迭代的每个项目迭代 Contents 数组。
<div *ngFor="let item of items">
<div *ngFor="let content of item.Contents">
{{content.Title}}
</div>
</div>
This is the stackblitz example i've made that shows both iterations.这是我制作的stackblitz 示例,显示了两次迭代。
I advice you to check Angular documentation about structural directives (ngIf,ngFor,...).我建议您查看有关结构指令(ngIf,ngFor,...) 的 Angular 文档。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.