I have a scenario, my child component takes BehaviourSubject as Input and that(child) subscribes it internally. I need to filter/map on BehaviourSubject in the parent, so that when somewhere next() is called then child subscription receives map/filtered values.
export class ParentComponent {
public myBSubject: BehaviorSubject<ListFilter[]> = new BehaviorSubject<ListFilter[]>(undefined);
public ngOnInit(): void {
this.myBSubject = this.myBSubject.pipe(
map((filters): ListFilter[] => {
// Do some manipulation with filters
return filters;
}));
}
}
tempalate
<child [myBSubject]="myBSubject"> </child>
ChildComponent (I have no control on it.)
export class ChildComponent {
@Input()
public myBSubject: BehaviorSubject<ListFilter[]> = new BehaviorSubject<ListFilter[]>(undefined);
// somewhere subscription of myBSubject
}
the problem is the .pipe(map) converting BehaviourSubject to Observable, which is not assignable. and without assigning map callback not called because immutable map.
by making
.pipe(map..) as BehaviourSubject<ListFilter>
working fine but i'm feeling its not a good solution.
Please help me to achieve this in a better way, Thank you.