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;
}
}