首页 > 解决方案 > matDialog上不存在Angular Material beforeClosed和afterAllClosed

问题描述

我正在尝试在我的视图上实现 matDialog,但在尝试使用 beforeClosed 时出错,它说它不是一个函数,但它在 matDialog 上也不存在。afterAllClosed 也是如此。
谁能帮助我?

Dialog:MatDialog;
constructor( Dialog:MatDialog ){ this.Dialog = Dialog; }

const DialogConfig = new MatDialogConfig();
DialogConfig.autoFocus = true;
DialogConfig.data = Provider;
this.Dialog.open(DialogComponent, DialogConfig);
this.Dialog.beforeClosed().subscribe(result => {
    console.log(`Dialog result: ${result}`);
})

类型“MatDialog”上不存在属性“beforeClosed”
错误类型错误:this.Dialog.beforeClosed 不是函数

标签: javascriptangularangular-material

解决方案


抱歉,我找到了解决方案,我需要获取正在打开的对话框的实例。

let CurrentDialog = this.Dialog.open(ProviderEditorComponent, DialogConfig);
CurrentDialog.beforeClosed().subscribe(result => {
  console.log(`Dialog result: ${result}`);
});

推荐阅读