簡體   English   中英

Angular:關閉 MatDialog

[英]Angular: Close a MatDialog

當我發出 HTTP 請求時,我正在打開加載 MatDialog。 但是,當我嘗試在呼叫訂閱中關閉它時,它不會關閉它。

我究竟做錯了什么?

      saveListOfSteps(isFormValid: boolean): void{

    if(isFormValid== false){
      alert("You have not filled out all fields in the form! Fix that first");
    }else{
      // show a loading dialog
      let dialogRefLoading = this.dialog.open(PopupComponent, {
        width: '250px',
        data: {
          data: ["Loading..."],
          showCloseButton: false},
      },    
      );
     dialogRefLoading.close;
     this.SelfServiceDetailsService.saveListOfSteps(this.validationSteps)
     .subscribe(response=>{
      dialogRefLoading.close;
       this.showSaveResultsDialog(response.body),
     error => alert("An error occured")});
    }

  }

close是 function 所以你必須這樣稱呼它

dialogRefLoading.close();

代替

 dialogRefLoading.close;

您在 else 條件中定義dialogRefLoading變量。 它應該在全球范圍內聲明。 並且close()是 function 不是Dialog class 中的屬性。 所以你應該使用dialogRefLoading.close()而不是dialogRefLoading.close


試試下面的代碼而不是你的代碼

saveListOfSteps(isFormValid: boolean): void {
    let dialogRefLoading = null;
    if (isFormValid == false) {
      alert("You have not filled out all fields in the form! Fix that first");
    } else {
      // show a loading dialog
      dialogRefLoading = this.dialog.open(PopupComponent, {
        width: '250px',
        data: {
          data: ["Loading..."],
          showCloseButton: false
        },
      },
      );          
      this.SelfServiceDetailsService.saveListOfSteps(this.validationSteps)
        .subscribe(response => {
          dialogRefLoading.close();
          this.showSaveResultsDialog(response.body),
            error => alert("An error occured")
        });
    }
  }

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM