提交后如何重置角度形式并设置默认值

d-s*_*all 4 angular angular-forms

我的预期结果是在提交表单后重置表单并将其默认值设置为绑定到 formGroup 控件。我试图在提交后通过在表单提交上调用 reset() 将表单重置为其默认数据。请告诉我如何重置日期和时间字段中的默认值。

例子 :

pickupDate = new Date().toISOString().slice(0,10);
pickupTime = moment().format() ;

onSubmit(orderData: Order){
        this.apiService(orderData).subscribe( order => {
                 orderForm.reset()
})
}
Run Code Online (Sandbox Code Playgroud)

请帮忙谢谢

Anu*_*ara 7

提交表格后。你在打电话

this.yourForm.reset()

然后你可以像这样将初始值修补到表单中。

this.yourForm.patchValue({
  firstControllerName: this.initialValues.value1,
  secondControllerName: this.initialValues.value2,
  // other controller names goes here
});
Run Code Online (Sandbox Code Playgroud)

希望这可以帮助。