api 正在返回嵌套对象,我在这里想要进入嵌套数组 并获取所有patato-child。
我还制作了所有的 Action 、效果、 reducer 。
Json View :
{
"id":13,
"patato":Patato
"patato-child":[
{
"id":12,
"name":"Adventure"
},
{
"id":18,
"name":"Drama"
}
],
"url":"randomUrl.jpg",
"example":"Example"
}
模型 View :
export interface Patato {
id: number;
patato: string;
url: string;
example: string;
patato-child: PatatoChild[];
}
export interface PatatoChild {
id: number;
name: string;
}
组件.ts
get patato-child() {
return this.patato.patatoChild;
}
HTML View :
[object Object, object Object]
这个结构有什么问题,我不能用 ngFor 得到任何 patato-child 来列出所有 patato child
I am using Angular 2+ Redux+@ngrx
最佳答案
试试这个:
export class PatatoChild {
constructor(public id: number, public name: string) {}
}
get patato-child() {
return this.patato.patatoChild.map(potato => new PatatoChild(potato.id, potato.name
}));
}
关于angular - 对象 Angular 2+ ngrx 中的嵌套数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44848122/