简体   繁体   English

MatDialog 子关闭父 MatDialog

[英]MatDialog Child Closes Parent MatDialog

I have a dialog that is used as popup window form.我有一个对话框用作弹出 window 表单。 When user gets error the dialog pops up a smaller dialog with error message and OK button.当用户遇到错误时,对话框会弹出一个带有错误消息和确定按钮的小对话框。

Clicking OK closes both matDialog windows.单击确定关闭 matDialog windows。

How can I get it to just close its self and not its parent?我怎样才能让它关闭它的自我而不是它的父母?

Parent =家长 =

<ng-template #dialogRef let-data>

Child =孩子 =

this.dialog.open(ErrorDialogComponent, { data: message });

I have tried using different scopes, but OK seems to close all dialog windows.我尝试过使用不同的范围,但 OK 似乎关闭了所有对话框 windows。

You can close a dialog programmatically with:您可以通过以下方式以编程方式关闭对话框:

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


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

I had the same problem.我有同样的问题。 This worked for me, though it's a slight workaround:这对我有用,虽然这是一个轻微的解决方法:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM