[英]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.