How can I transfer values from an Observable to an other Observable?
How can achive it that "getObs" Observable have value from subscribe in OnInit method. I need getObs on html template for async pipe.The value (Mydata) what is comming from input decorator is a "Observable(boolean)" type.This is something with pipe and map i think but im not sure.
@Component({
templateUrl: 'my.html',
styleUrls: ['my.scss'],
})
export class MyClass implements OnInit {
@Input() data: ;
getObs$: Observable<boolean>;
ngOnInit(): void {
this.data.myData.subscribe(x=>.....???)
}
}
That's a standard scenario for using switchMap()
, but you use this inside of .pipe()
instead of .subscribe()
.
ngOnInit(): void {
this.data.myData.pipe(
switchMap(myDataValue => getObs$.pipe(
map(getObsValue => {
// Do something with 'myDataValue' and 'getObsValue'
)
)
).subscribe();
}