Form field initiates with "required" error in Angular

Issue

I’m working with a form field that is required to the form, but when the page loads the field already starts with "required" error and it should appear only after the user type something or don’t. I’m using mat-error and validators in the form with Angular 12.

Solution

You need to check for dirty or touched property.

Something like:

*ngIf="name.invalid && (name.dirty || name.touched)"

Answered By – robert

Answer Checked By – Senaida (AngularFixing Volunteer)

Leave a Reply

Your email address will not be published.