角度对话框:如何根据状态打开或关闭按钮
我正在使用对话框组件,并且在打开对话框时需要主按钮来关闭对话框。 我正在使用对话框而没有背景覆盖,因为在打开对话框时,我需要用户与页面进行交互。对话框的关闭按钮可以正常工作。 我尝试了带有新变量的@Input,然后尝试了GetState和MatdialogState而没有成功,我只是打破按钮。我找不到任何例子。 这是我的代码:
export class DialogButton {
constructor(
public dialog: MatDialog,
public dialogRef: MatDialogRef<DialogComponent>,
) { }
toggleDialog() {
this.dialog.open(DialogComponent, {
id: 'legend-button-dialog-container',
disableClose: false,
hasBackdrop: false,
});
}
}
I am using the Dialog component and I need the main button to close the dialog when the dialog is opened.
I am using the dialog with no backdrop overlay because I need the user to interact with the page while the dialog is opened. The close button of the dialog works fine.
I tried the @input with a new variable and I tried the getState and MatDialogState without success, I just break my button. I couldn't find any examples.
Here is my code :
export class DialogButton {
constructor(
public dialog: MatDialog,
public dialogRef: MatDialogRef<DialogComponent>,
) { }
toggleDialog() {
this.dialog.open(DialogComponent, {
id: 'legend-button-dialog-container',
disableClose: false,
hasBackdrop: false,
});
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
尝试这样的事情,应该起作用
try something like this, should work
上面的代码生成了一个问题,如果我们使用“关闭”按钮关闭对话框,则需要在对话框按钮上两次插入对话框才能打开它。此代码修复了它:
the code above generated an issue, if we close the dialog using the close button, we needed to clic twice on the dialog button to open it. This code fixed it: