Home > Mobile >  Form field initiates with "required" error in Angular
Form field initiates with "required" error in Angular

Time:09-21

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.

CodePudding user response:

You need to check for dirty or touched property.

Something like:

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