How to reset only specific fields of form in angular 5

前端 未结 5 2272
名媛妹妹
名媛妹妹 2021-02-19 20:45

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!\")         


        
5条回答
  •  囚心锁ツ
    2021-02-19 21:21

    try this one:

      clearForm() {
        this.myForm.get('comments').reset();
        this.myForm.get('name').reset();
      }
    

    and call this function where you submit form.

提交回复
热议问题