如何仅重置角度 5 中的特定表单字段 [英] How to reset only specific fields of form in angular 5

查看:18
本文介绍了如何仅重置角度 5 中的特定表单字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的一个组件文件中创建了一个函数来重置表单(myform):

I have created a function in one of my component file that resets the form(myform):

`onSubmit() {
  if (this.myform.valid) {
    console.log("Form Submitted!");
    this.myform.reset();
  }
}`

它可以很好地重置整个表单,但是否可以只重置一些元素并保持其他元素不变.

It works perfectly fine resetting the whole form, but is it possible to just reset some of the elements and keeping other the same way.

推荐答案

试试这个:

this.myform.controls['comments'].reset()

这篇关于如何仅重置角度 5 中的特定表单字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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