0
我正试图return
从另一个observable的订阅中获得布尔值。然而,我不能让return
泡泡到父方法。在子订阅中返回parent observable
我知道我是return
在订阅的上下文中,但我如何告诉canDeactive
dialog.result.subscibe
订阅完成并且能够返回布尔值?
canDeactivate(): Observable<boolean> | Promise<boolean> | boolean {
const settings: DialogSettings = {
title: 'Please confirm',
content: 'Are you sure want to leave without saving your changes?',
actions: [
{ text: 'No'},
{ text: 'Yes', primary: true }
]
};
if (!this.isSaved && this.updatedPositions.length) {
// return confirm('Do you want to discard the changes?');
const dialog: DialogRef = this.dialogService.open(settings);
dialog.result.subscribe((result: DialogResult) => {
if (!(result instanceof DialogCloseResult) && result['text'] === 'Yes') {
console.log('action', result);
console.log('returning false');
return false;
} else {
console.log('dialog.close()');
dialog.close();
return true;
}
})
} else {
console.log('else');
return true;
}
}