【发布时间】:2019-05-29 23:18:48
【问题描述】:
HTML:
<form [formGroup]="locationForm" #myForm="ngForm" class="formContainer">
<div class="buttonContainer">
<section class="btn1">
<button
(click)="addAnotherMethod()"
mat-raised-button
color="primary"> Add another method </button>
</section>
<section>
<button
(click)="addAnotherLocation()"
mat-raised-button
color="primary"> Add another location </button>
</section>
</div>
.TS 文件
@ViewChild('myForm') currentLocationForm;
addAnotherLocation(): void{
if(this.locationForm.valid){
//send data to redux
}))
}
this.currentLocationForm.resetForm()
}
addAnotherMethod: void {
if(this.locationForm.valid){
//send data to redux
}))
}
this.currentLocationForm.resetForm()
}
使用上面的代码,我可以在数据发送到 redux 后重置表单,但是在重置后,新表单中的验证错误消息会出现,说要填写必填字段。我需要帮助来使用正确的方法来重置此表单并在显示新表单时清除验证。我也可能使用错误的方法来调用两个按钮功能。 谢谢。
【问题讨论】:
-
你能提供stackblitz吗?
标签: angular angular-material angular7 angular-reactive-forms