How to clear form after submit in Angular 2?

后端 未结 15 1481
遇见更好的自我
遇见更好的自我 2020-12-02 16:10

I have some simple angular 2 component with template. How to clear form and all fields after submit?. I can\'t reload page. After set data with date.setValue(\'\')

15条回答
  •  离开以前
    2020-12-02 17:08

    Make a Call clearForm(); in your .ts file

    Try like below example code snippet to clear your form data.

    clearForm() {
    
    this.addContactForm.reset({
          'first_name': '',
          'last_name': '',
          'mobile': '',
          'address': '',
          'city': '',
          'state': '',
          'country': '',
           'zip': ''
         });
    }
    

提交回复
热议问题