Within Angular 8, I am dealing with an Observable:
let parents: Observable<Parent[]>;
The classes Parent
and Child
are defined as follows:
class Parent {
id: number;
name: string;
children: Child[];
}
class Child {
id: number;
name: string;
}
My goal is to locate the specific Child
whose id
value is 1 across all children of the parents.
Following that, I must establish a condition involving that particular Child
and its respective Parent
... I attempted it like this:
parents.pipe(
map(parents => parents.map(parent => parent.children)),
map(children => children.find(child => child.id == 1))
map(child => Test Condition with resulting Child and its Parent
A challenge arose when I discovered that the variable children
in the line map(children =>
is of type Child[][]
rather than Child[]
, causing the expression child.id
to fail due to child
being of type Child[]
.
Additionally, in the final map function, I require not only the Child
object but also its associated Parent
in order to construct the condition and return an Observable<boolean>
Is there a way to accomplish this? Is it impossible using map?