Form field initiates with "required" error in Angular

Viewed 112

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.

1 Answers

You need to check for dirty or touched property.

Something like:

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