Angular(TS)でネストされているjsonオブジェクトをモデルにアサインしたいと思っています。
1階層目は問題なく取得できるのですが、2階層目以降はchannelsの中身がnullになります。
- json
[ { "id": 1, "parent_id": null, "user_id": 1, "name": "D1", "channel": [ { "id": 4, "parent_id": 1, "user_id": 1, "name": "D11", "channel": [], "created_at": "2018-06-23T06:58:30Z", "updated_at": null }, ], "created_at": "2018-06-23T06:58:30Z", "updated_at": "2018-06-23T17:23:19Z" } ]
- entity
export class Channel { id: number; name: string; channels: Channel[]; }
- service
/** GET channels from the server */ getChannels (): Observable<Channel[]> { return this.http.get<Channel[]>(this.channelsUrl) .pipe( tap(channels => this.log(`fetched channel`)), catchError(this.handleError('getChannels', [])) ); }
モデルに再帰的に値をアサインする方法はありませんでしょうか。
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2018/07/07 01:15
2018/07/07 04:55
2018/07/08 02:09
2018/07/08 02:22 編集