Skip to main content
Practice Problems

Difference between template-driven and reactive forms in Angular

What are Forms in Angular?

In Angular there are two approaches to creating forms:

  1. Template-driven forms — forms built based on templates (HTML).
  2. Reactive forms — forms managed from TypeScript code.

Comparison Table

CharacteristicTemplate-driven FormsReactive Forms
FoundationHTML templateTypeScript code
ModuleFormsModuleReactiveFormsModule
ManagementDeclarative (via template)Imperative (via code)
ApproachLight, declarativeFlexible, programmatic
ValidationVia HTML attributes + directivesVia API and methods
TestingMore complexEasier
Suitable forSimple formsComplex/dynamic forms

Template-driven Form Example

html
<form #userForm="ngForm" (ngSubmit)="onSubmit(userForm)"> <input name="username" ngModel required /> <input name="email" ngModel email /> <button type="submit">Submit</button> </form>
typescript
onSubmit(form: NgForm) { console.log(form.value); }
  • Uses ngModel for data binding.
  • Directives (required, email) for validation.
  • Logic is in template.

Reactive Form Example

typescript
import { FormGroup, FormControl, Validators } from '@angular/forms'; form = new FormGroup({ username: new FormControl('', Validators.required), email: new FormControl('', [Validators.required, Validators.email]) }); onSubmit() { console.log(this.form.value); }
html
<form [formGroup]="form" (ngSubmit)="onSubmit()"> <input formControlName="username" /> <input formControlName="email" /> <button type="submit">Submit</button> </form>
  • Management completely in TS code.
  • Validation set in FormControl via Validators.
  • Better suited for complex scenarios.

When to Use?

ScenarioRecommended approach
Simple login formTemplate-driven
Complex dynamic form with logic and validationReactive
Need for scaling and testingReactive
Quick and simple form implementationTemplate-driven
Important: Both approaches can be combined, but better choose one and stick with it throughout project for consistency.

Content

What are Forms in Angular?Comparison TableTemplate-driven Form ExampleReactive Form ExampleWhen to Use?

Short Answer

Interview ready
Premium

A concise answer to help you respond confidently on this topic during an interview.

Finished reading?
Practice Problems