简体   繁体   English

角材料对话框

[英]angular material dialog box

I am using angular material dialog box.我正在使用角材料对话框。 currently its open.目前它是开放的。 but i do not know how it close using dialog box close button.但我不知道它是如何使用对话框关闭按钮关闭的。 i tried several times, but could not do it.我尝试了几次,但无法做到。 please check below code (part of code)请检查下面的代码(代码的一部分)

      constructor(private summaryService: SummaryService,public dialog: MatDialog) { }
  openDialog(): void {
    const dialogRef = this.dialog.open(ConfirmationDialog, {
    });


  }

  closeDialog(){
    alert("test");
    this.dialog.close();
  }

openDialog() is working well. openDialog() 运行良好。 i have two problems in the colseDialog() function.我在 colseDialog() 函数中有两个问题。 when i alert some text, error " _co.closeDialog is not a function".当我提醒一些文本时,错误“_co.closeDialog 不是函数”。 other error display in my IDE "Property 'close' does not exist on type 'MatDialog'".我的 IDE 中显示其他错误“'MatDialog' 类型上不存在属性 'close'”。 can u give solution to close popup你能给出关闭弹出窗口的解决方案吗

Try making dialogRef global variable in main.component.ts尝试在 main.component.ts 中创建 dialogRef 全局变量

dialogRef : MatDialogRef<ConfirmationDialog>

constructor(private summaryService: SummaryService,public dialog: MatDialog) { }

openDialog(): void {
   dialogRef = this.dialog.open(ConfirmationDialog, {
   });
}

closeDialog(){
   alert("test");
   this.dialogRef.close();
}

Try following changes in your confirmationDialog.component.ts尝试在您的 ConfirmationDialog.component.ts 中进行以下更改

constructor(
@Inject(MAT_DIALOG_DATA) public data: any,
public dialogRef: MatDialogRef<ESignatureComponent>,
 ) { }

onCloseClick(){
  this.dialogRef.close();
}

You can try something like this, you have to listen to the close event in the method where you declared your dialogRef object, otherwise it will be undefined.您可以尝试这样的操作,您必须在声明 dialogRef 对象的方法中监听 close 事件,否则它将是未定义的。

openDialog(): void {
   const dialogRef = this.dialog.open(ConfirmationDialog);
   dialogRef.afterClosed().subscribe(result => {
      if(result) {
        //Means user clicked on OK button
      }
    });
}

You can use afterOpened event to get modal Window globally.您可以使用 afterOpened 事件来全局获取模态窗口。

export class AppComponent implements OnInit, OnDestroy {
  dialogRef: MatDialog;

  constructor(@Inject(DOCUMENT) private _document: Document, public store: Store, dialog: MatDialog) {
    this.dialogRef = dialog;
    this.dialogRef.afterOpened.subscribe(value => {
      console.log("Some Modal Window Opened");
    })
  }

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

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