Using the NgForm directive

We have already mentioned that the form directive enhances the HTML5 form's behavior by adding some additional Angular-specific logic. Now, let's take a step back and take a look at the form that surrounds the input elements:

<form #f="ngForm" (ngSubmit)="addDeveloper()" 
      class="form col-md-4" [hidden]="submitted"> 
  ... 
</form> 

In this snippet, we define a new identifier called f, which references to the form. We can think of the form as a composition of controls; we can access the individual controls through the controls property of the form. On top of this, the form has the touched, untouched, pristine, dirty, invalid, and valid properties, which depend on the individual controls defined within the form. For example, ...

Get Switching to Angular - Third Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.