Skip to content

Instantly share code, notes, and snippets.

@rlunaro
Last active October 13, 2022 11:54
Show Gist options
  • Save rlunaro/ce4732054870b93b72b3d1aab4d4ff89 to your computer and use it in GitHub Desktop.
Save rlunaro/ce4732054870b93b72b3d1aab4d4ff89 to your computer and use it in GitHub Desktop.
Notes on Angular Validators

Some notes on validators

A model of the for that can be accessed in the code

<form (ngSubmit)="onSubmit( f )" #f="ngForm">

In the code we can access this form as:

onSubmit( form : NgForm ) {
  console.log( form );
}

An example of a validator of a single field

   <div class="form-group">
     <label for="email">Mail</label>
     <input 
       type="email" 
       id="email" 
       class="form-control"
       ngModel
       name="email"
       required email
       #email="ngModel">
       <span class="help-block" *ngIf="!email.valid">Please enter a valid email</span>
   </div>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment