Nested array in Angular 2+ ngrx object

Api returns nested objects, I want to enter a nested array here and get all patato-child .

I also did all the actions, effects, gears.

Json view:

{  
  "id":13,
  "patato":Patato
    "patato-child":[  
       {  
        "id":12,
        "name":"Adventure"
       },
       {  
        "id":18,
        "name":"Drama"
       }
     ],
   "url":"randomUrl.jpg",
   "example":"Example"
}

Type of model:

export interface Patato {
    id: number;
    patato: string;
    url: string;
    example: string;
    patato-child: PatatoChild[];
}

export interface PatatoChild {
    id: number;
    name: string;
}

Componentent.ts

  get patato-child() {
    return this.patato.patatoChild;
  } 

HTML view:

[object Object, object Object]

What is wrong with this structure, I cannot get any patato-child with ngFor to list the whole child patato

I am using Angular 2+ Redux + @ngrx

+4
source share
1 answer

Try the following:

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
    }));
} 
+3
source

Source: https://habr.com/ru/post/1680504/


All Articles