In one of my components I have a function that updates a local observable (album$
) which is then used in my html to display the data (*ngIf="album$ | async as album"
). This works perfectly fine.
getData() {
this.album$ = this._activatedRoute.params.pipe(
tap(params => {
// Update variables
}),
switchMap(params => {
return this.service.getData(params.id, params.id2);
})
)
}
However, a new requirement means that I need to update a BehaviorSubject I have in one of my services. The function above seemed like a great place to kill two birds with one stone.
I would like to perform a patchValue
and this.service.obs$.next
once the function above returns it's data.
I do achieve this functionality in a separate component I have, but as I'm not using a subscription in the one above, how would i go above adding this.service.album$.next(data);
to my above function?
// Example of another function that has the functionality i'm pretty much after, but is subscription based.
getData(){
this._subscription = this._activatedRoute.params.pipe(
tap(params => {
// update variables
}),
switchMap(params => {
return this.service.getData(params.id1, params.id2);
})
).subscribe(data => {
if (data) {
this.service.obs$.next(data);
}
});
}