Form field initiates with "required" error in Angular


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.


You need to check for dirty or touched property.

Something like:

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

Answered By – robert

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply

(*) Required, Your email will not be published