How to reset only specific fields of form in angular 5
Yes you can access the controls using this.myform.controls
get the control and call reset()
on it
try this:
this.myform.controls['comments'].reset()
UPDATE:
I just had this issue and although the accepted answer works, it has some tslint warnings. I ended up doing:
this.myForm.get('formControlName').setValue(null);
I'm working with Angular 8.
And if you want to do it for several fields this works too:
private controlNames = ['nameOne', 'nameTwo'];
this.controlNames.map((value: string) => this.myForm.get(value).setValue(null));
try this one:
clearForm() {
this.myForm.get('comments').reset();
this.myForm.get('name').reset();
}
and call this function where you submit form.