提交后如何重置角度形式并设置默认值 [英] how to reset angular form and set default values after submitting

查看:81
本文介绍了提交后如何重置角度形式并设置默认值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

My expected results is to reset the form after it has been submit and set its default values binded to the formGroup control. I am attempt to reset the form to its default data after submitting by calling reset() on the form submit. Please advise me on how can I reset the default value in the date and time field .

示例:

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

onSubmit(orderData: Order){
        this.apiService(orderData).subscribe( order => {
                 orderForm.reset()
})
}

请帮助谢谢

推荐答案

提交表单后.您正在呼叫

After submitting your form. you are calling

this.yourForm.reset()

然后,您可以将初始值修补到这种形式.

Then you can patch initial values to the form like this.

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

希望这会有所帮助.

这篇关于提交后如何重置角度形式并设置默认值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆