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

查看:87
本文介绍了如何仅重置角度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天全站免登陆