小编Ale*_*ili的帖子

Angular 6 MatDialog 取消关闭事件

我有两个组件:CustomerComponentCustomerCreateUpdateComponent

CustomerComponent包括客户数据表。 CustomerCreateUpdateComponent是一个带有用于创建/更新的输入控件的表单。

mat-dialogCustomerCreateUpdateComponent它。打开对话框并填写表格后,我单击提交按钮并this.dialogRef.close(customer);执行。customer对象具有所有值。

CustomerComponent我已经subscribethis.dialog.open(CustomerCreateUpdateComponent).beforeClose().subscribe((customer: Customer) => { ... });

这是beforeClose()方法,所以在对话框关闭之前,我取回customer对象并将其发布到 api。

如果 POST 成功,一切正常,对话框关闭并更新数据表。

但是,如果 POST 没有成功,api 将返回一个错误,我想向用户显示并保持对话框打开,类似于if(error) { closeEvent.cancel() }

我看过整个文档mat-dialog,没有任何帮助。我几乎可以肯定没有办法做到这一点。

也许有人有同样的问题?很高兴听到任何解决方法。

material-design angular-material angular angular6

5
推荐指数
2
解决办法
2万
查看次数