Can you explain what the of()
function creates in this scenario and how it operates?
public onRemoving(tag): Observable<any> {
const confirm = window.confirm('Do you really want to remove this tag?');
return Observable.of(tag).filter(() => confirm);
}
I attempted to customize it for my specific situation:
const confirm = false;
this.mapDlg
.confirm(args)
.subscribe(res => {
if (res != null) {
confirm = true;
}
});
return Observable
.of(tag)
.filter(() => confirm);
However, I encountered an issue as .confirm()
returns an Observable where I capture the value of confirm
I also experimented with a different approach:
public onRemoving(tag: any): Observable<any> {
const args = new MultiDlgArgs();
args.type = 'confirmation';
return Observable.create(observer => {
return this.mapDlg
.confirm(args)
.subscribe(res => {
return false;
});
});
}
One more method I tested was:
public onRemoving(tag: any): Observable<any> {
const args = new MultiDlgArgs();
args.type = 'confirmation';
return new Observable<boolean>(observer => {
this.mapDlg
.confirm(args).map((res) => {
if (res == null) {
observer.next(false);
} else {
observer.next(true);
}
});
}
);
}