What is Template Driven feature in Angular?

TDF- Features:

  • Easy to use
  • Template driven forms are simple and straightforward
  • All the validations, form elements are all defined in the template file
  • Forms are tracked automatically
  • Tracked form data traverses via various states
  • Uses two-way data binding techniques to bind data
  • Most of the code resided in template file
  • Validations are mostly the default HTML5 validations
  • Minimal component code as most of the code is in template file
  • Unit testing will be a challenge

How to use TDF:

  • We will need to import FormsModule in app module to work with TDF
  • Step 1 : import and add in the FormsModule in the app.module.ts
  • Step 2: create the form in app.component.html
  • ngForm dash; form name as template variable using ‘#’
  • ngModel dash; every form field should have a name attribute and ngModel attached to it