0

I am new in angular 6 and working on a angular project.I am facing a problem while reset the form after submission of the form.Here is code:

<form [formGroup]="commentForm">
<div class="col-md-8 "  [ngClass]="{ 'is-invalid': submitted && f.comment.errors }">
   <textarea class="form-control" [(ngModel)]="commentsData.comment"   [ngClass]="{ 'is-invalid': submitted && f.comment.errors }" formControlName="comment" placeholder="Add a Comment..." rows="5" cols="8"> </textarea>
</div>
</form>

in components.ts file i am using this for reset the form

 this.commentForm.reset();

Form values are cleared successfully,but only problem is after reset form field border is in red color. I am trying

this.commentForm.markAsPristine();

But nothing helps

Karan
  • 1,048
  • 2
  • 20
  • 38

1 Answers1

1

You can setErrors to null for your form after reset.

for( let i in this.commentForm.controls ) {

        this.commentForm.controls[i].setErrors(null);
}
Hien Nguyen
  • 24,551
  • 7
  • 52
  • 62