I am trying to find best way to reset angular reactive form. I'm bit confused for reset reactive forms and not able to find which method is for template driven forms and which is reactive forms. Now I've used 'formGroupDirective' to reset but I'm getting console error like below.
this is how I have used formGroupDirective for reset.
Template file:
<form
...
#formDirective="formGroupDirective"
>
TS file:
import { ViewChild, ... } from '@angular/core';
import { FormGroupDirective, ... } from '@angular/forms';
export class MyComponent {
...
@ViewChild('formGroupDirective') private formGroupDirective: FormGroupDirective;
constructor(... )
private someFunction(): void {
...
formGroupDirective.resetForm();
}
}
Here I couldn't understand one thing, What is the difference between FormGroupDirective and FormDirective. And which one is preferable for reactive forms. And even we can reset through formGroup name like
this.formGroup.reset();
So If we can able to reset through formGroup name, then why we need to use directives. If any one have idea please help me to understand these differences.