Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

how to set a custom error message to a form in angular

<span
      *ngIf="
        !loginForm.get('email')?.valid &&
        (loginForm.get('email')?.touched || loginForm.get('email')?.dirty)
      "
    >
      {{
        loginForm.get('email')?.hasError('required')
          ? 'Username Required'
          : loginForm.get('email')?.getError('invalid')
      }}

</span>
 this.loginForm.get('email')?.setErrors({ invalid: 'Invalid Username' });
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #set #custom #error #message #form #angular
ADD COMMENT
Topic
Name
6+8 =