Lesson 17 / 30

Template-Driven Forms

Build simple forms mostly in the template with ngModel.

A basic form

ngModel on each field builds up the form's value; ngSubmit fires when the form is submitted.

<form #f="ngForm" (ngSubmit)="onSubmit(f.value)">
  <input name="email" [(ngModel)]="email" required>
  <button type="submit">Sign up</button>
</form>

Good for simple cases

Template-driven forms suit short, simple forms. Angular manages the form model behind the scenes, so there's less TypeScript to write.