Sitemap

Forms in Angular: Reactive vs. Template-Driven — Which One Will Ruin Your Weekend?

3 min readMay 3, 2025

--

Press enter or click to view image in full size

Let’s face it — forms in Angular are like dating apps: there’s the one that looks easy at first (Template-Driven), but soon ghosted you with a mysterious bug, and the one that demands effort upfront (Reactive), but ends up giving you stability and self-worth (well, kind of).

In this no-nonsense, slightly passive-aggressive guide, we’ll dissect the two main ways Angular makes you suffer (read: build forms), discover what’s new in Angular 14+ (spoiler: TypeScript fans rejoice), and settle the debate once and for all — or at least until Angular drops another major release and everything breaks again.

1. REACTIVE FORMS

Code-driven, more scalable and predictable.

Form model is defined in the component.

Strong TypeScript support.

Preferred for complex and dynamic forms.

How to Create a Reactive Form

Step 1: Import ReactiveFormsModule

In app.module.ts:

import { ReactiveFormsModule } from '@angular/forms';

@NgModule({
imports: [
ReactiveFormsModule
]
})
export class AppModule {}

Step 2: Create Form in Component (with FormBuilder)

import { Component } from '@angular/core';
import { FormBuilder, FormGroup, Validators } from '@angular/forms';

@Component({
selector: 'app-reactive-form',
templateUrl: './reactive-form.component.html'
})
export class ReactiveFormComponent {
userForm: FormGroup;

constructor(private fb: FormBuilder) {
this.userForm = this.fb.group({
name: ['', [Validators.required, Validators.minLength(3)]],
email: ['', [Validators.required, Validators.email]],
age: [null, [Validators.required, Validators.min(18)]],
});
}

onSubmit() {
if (this.userForm.valid) {
console.log(this.userForm.value);
}
}
}

Step 3: Template (reactive-form.component.html)

<form [formGroup]="userForm" (ngSubmit)="onSubmit()">
<input formControlName="name" placeholder="Name">
<div *ngIf="userForm.get('name')?.invalid && userForm.get('name')?.touched">
Name is required (min 3 characters)
</div>
<input formControlName="email" placeholder="Email">
<div *ngIf="userForm.get('email')?.invalid && userForm.get('email')?.touched">
Enter a valid email
</div>
<input formControlName="age" type="number" placeholder="Age">
<div *ngIf="userForm.get('age')?.invalid && userForm.get('age')?.touched">
Age must be at least 18
</div>
<button type="submit" [disabled]="userForm.invalid">Submit</button>
</form>

What’s New in Angular 14+ (Reactive Forms)

Typed Forms (Strong Typing)

Angular 14+ introduces strongly typed forms. Instead of FormGroup<any>, you can now use:

userForm: FormGroup<{
name: FormControl<string>;
email: FormControl<string>;
age: FormControl<number | null>;
}>;

This allows IDE auto-complete and better type safety!

2. TEMPLATE-DRIVEN FORMS

Simpler syntax, suitable for simple forms.

Form logic is in the HTML template.

Angular handles form model creation under the hood.

How to Create a Template-Driven Form

Step 1: Import FormsModule

In app.module.ts:

import { FormsModule } from '@angular/forms';
@NgModule({
imports: [
FormsModule
]
})
export class AppModule {}

Step 2: Component Template

<form #userForm="ngForm" (ngSubmit)="onSubmit(userForm)">
<input name="name" [(ngModel)]="user.name" required minlength="3" #name="ngModel">
<div *ngIf="name.invalid && name.touched">
Name is required (min 3 chars)
</div>
<input name="email" [(ngModel)]="user.email" required email #email="ngModel">
<div *ngIf="email.invalid && email.touched">
Enter valid email
</div>
<input name="age" [(ngModel)]="user.age" type="number" required min="18" #age="ngModel">
<div *ngIf="age.invalid && age.touched">
Age must be 18+
</div>
<button type="submit" [disabled]="userForm.invalid">Submit</button>
</form>

Step 3: Component Class

import { Component } from '@angular/core';

@Component({
selector: 'app-template-form',
templateUrl: './template-form.component.html'
})
export class TemplateFormComponent {
user = {
name: '',
email: '',
age: null
};
onSubmit(form: any) {
if (form.valid) {
console.log(this.user);
}
}
}

Both the Reactive & Template-Driven Forms have their own use cases, strengths, and ways to handle form creation, validation, and value handling.

Get Apoorv Verma’s stories in your inbox

Join Medium for free to get updates from this writer.

For a quick summary, refer to the table below-

Press enter or click to view image in full size

And there you have it — Reactive Forms for the control freaks, Template-Driven for the free spirits who trust Angular a little too much.

Remember: whichever form you choose, the real validation is inside you (but also in your Validators.required).

Now go forth, build forms, and may your FormGroup never be null and your ngModel never mysteriously lose binding mid-demo.

Until next time — keep your code dry, your humor dark, and your bugs… someone else’s problem.

--

--