Validating the form and form fields

Angular greatly simplifies form validation by using its built-in directives and state properties. You can use the state property to check whether a form field has been touched. If it's touched but violates a validation rule, you can use the ngIf directive to display associated errors.

Let's see an example of validating the full name field:

<div class="form-group">    <label for="fullName">Full Name</label>    <input       type="text"       id="fullName"       class="form-control"       [(ngModel)]="flightModel.fullName"       name="fullName"      #name="ngModel"      required      minlength="6">  </div>

We just added three extra significant attributes to our form's full name field: #name, required, and minlength. The #name attribute is completely different ...

Get TypeScript 2.x for Angular Developers now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.