After receiving a structured response from an API,
I come across the following signature:
methodApi(): Observable(Array<MyClass>)
The data looks like this:
{ id: 1, name: 'Red', parentId: null }
{ id: 2, name: 'Apple', parentId: 1 }
others
My goal is to group this data by parentId.
methodApi()
.pipe(groupby((x: MyClass[] => ...))) // THIS IS WHERE THE ISSUE LIES
.subscribe(x => console.log(x));
The methodApi returns Observable<Array>. The problem arises when I attempt to reference the parentId property within the 'groupby' method since it requires an array as input and not a specific object like MyClass.
How can I effectively resolve this grouping issue?
Running Angular 9.0 with RxJS 6.5.5