1

我在垫子对话框中有一个垫子菜单。打开对话框然后打开其中的菜单后,我按 esc 关闭菜单,但菜单和对话框都关闭了。如何只关闭菜单而不是用 ESC 关闭对话框?

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

4

1 回答 1

0

您可以添加disableClose: truedialogRef配置中,以防止对话框关闭按escDialog 组件的 API 中对此进行了说明。

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

请参阅此更新的 StackBlitz以供参考。

于 2020-09-25T10:34:58.607 回答