MatDialog子级关闭父级MatDialog

时间:2019-11-05 17:21:04

标签: angular dialog angular-material material-design

我有一个用作弹出窗口形式的对话框。当用户遇到错误时,该对话框会弹出一个带有错误消息和“确定”按钮的较小对话框。

单击“确定”关闭两个matDialog窗口。

我如何才能使其仅封闭自身而不是封闭自身?

父母=

@Field((type) => UserSettingsType)
settings: SettingsScalar (replace by however you call your new type)

孩子=

<ng-template #dialogRef let-data>

我尝试使用不同的作用域,但是“确定”似乎关闭了所有对话框窗口。

2 个答案:

答案 0 :(得分:0)

您可以通过以下方式以编程方式关闭对话框:

constructor(private dialogRef: MatDialogRef<MyComponentToClose>){}


closeComponent(){
   this.dialogRef.close()
}

答案 1 :(得分:0)

我有同样的问题。这对我有用,尽管这是一个小解决方法:

<button class="btn" mat-dialog-close="">Close</button>