resetting reactive form triggers all required validators in Angular 6

后端 未结 2 1979
佛祖请我去吃肉
佛祖请我去吃肉 2021-01-19 23:38

I am new to angular 6 ,Here I am trying to reset the form after submitting the data.

Everything works fine but when I reset the form after successful data submit to

2条回答
  •  梦谈多话
    2021-01-20 00:41

    Thats great solution but, reactive forms have their own feature to do so.

    You can remove validations on specific formGroup/formcontrol by using clearValidators() for reactive forms.

    this.formGroup.clearValidators() or      
     this.formGroup.controls.controlName.clearValidators()
    

    After this, you have to update form control with the removed validator

    this.formGroup.controls.controlName.updateValueAndValidity()
    

    This helped me to resolve same issue, hope it helps you too

提交回复
热议问题