I have an Observable (commonSrv.uiMessage) which I am listening to. When it fires I show a message to the user (this.snackBar.open) and receive a ref (snackBarRef) as a result. When the user clicks on the message, onAcation() is fired and I receive a new Observable.
I want to take this Observable returned from snackBarRef.onAction() and listen to it somewhere else.
commonSrv.uiMessage.subscribe((msg) => {
let snackBarRef = this.snackBar.open(msg.text , msg.actionTxt);
snackBarRef.onAction().subscribe(() => {
alert('The snack-bar action was triggered!');
});
})
I know I can't send an Observable from within a subscription, so this does not work
let x = new Observable<any>()
commonSrv.uiMessage.subscribe((msg) => {
let snackBarRef = this.snackBar.open(msg.text , msg.actionTxt);
x = snackBarRef.onAction()
});
x.subscribe(a=> alert(a))
I should probably use pipe and map to funnel the original Observable but am not sure of the syntax or which operators are suitable (map? switchMap?)