我有两个组件:
我有一个
在
如果POST成功,一切正常,对话框关闭且数据表已更新。
但是,如果POST失败,API将返回错误,我希望向用户显示错误并保持对话框打开,例如
也许有人遇到过同样的问题?很高兴听到任何解决办法。
CustomerComponent
和CustomerCreateUpdateComponent
。
CustomerComponent
包括客户数据表。
CustomerCreateUpdateComponent
是一个带有输入控件的用于创建/更新的表单。我有一个
mat-dialog
,其中包含CustomerCreateUpdateComponent
。
在打开对话框并填写表单后,单击提交按钮,执行this.dialogRef.close(customer);
。 customer
对象具有所有值。在
CustomerComponent
中,我订阅了this.dialog.open(CustomerCreateUpdateComponent).beforeClose()。subscribe((customer:Customer)=> {...});
这是beforeClose()
方法,因此在对话框关闭之前,我会返回customer
对象并将其POST到API。如果POST成功,一切正常,对话框关闭且数据表已更新。
但是,如果POST失败,API将返回错误,我希望向用户显示错误并保持对话框打开,例如
if(error) {closeEvent.cancel()}
我已经查看了整个mat-dialog
文档,但没有发现有用的信息。 我几乎可以确定没有方法可以做到这一点。也许有人遇到过同样的问题?很高兴听到任何解决办法。