我在Mat对话框中有一个Mat菜单。打开对话框,然后打开其中的菜单后,按esc键关闭菜单,但菜单和对话框均关闭。如何仅关闭菜单而不关闭带有ESC的对话框?
答案 0 :(得分:0)
您可以将disableClose: true
添加到dialogRef
配置中,以防止对话框关闭时按 esc 。是explained in the API of the Dialog component。
disableClose: boolean
用户可以使用转义还是单击背景来关闭模式。
openDialog(): void {
const dialogRef = this.dialog.open(DialogOverviewExampleDialog, {
width: '250px',
data: {name: this.name, animal: this.animal},
disableClose: true
});
dialogRef.afterClosed().subscribe(result => {
console.log('The dialog was closed');
this.animal = result;
});
}
请参阅this updated StackBlitz以供参考。