我在“材质”对话框中有一个“角度材质”菜单。按下ESC时,菜单和对话框均关闭。如何防止在ESC上对话框无法关闭?

时间:2020-09-25 10:32:14

标签: angular angular-material material-dialog

我在Mat对话框中有一个Mat菜单。打开对话框,然后打开其中的菜单后,按esc键关闭菜单,但菜单和对话框均关闭。如何仅关闭菜单而不关闭带有ESC的对话框?

可以在此处复制。 https://stackblitz.com/edit/angular-wzau6u

1 个答案:

答案 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以供参考。

相关问题