Full answer
Both styles produce the same result, a form with values and validation state. They differ in where the form model lives.
Template-driven forms use directives such as ngModel in the HTML. Angular builds the model behind the scenes. They are quick for a login box, but validation rules are spread through the template and are harder to unit test. They need FormsModule.
Reactive forms build the model in the class. You create FormGroup and FormControl objects (often with FormBuilder), and bind them in the template with [formGroup] and formControlName. They need ReactiveFormsModule. The model is plain code, so you can test it without rendering, read its value as a stream (valueChanges), and change it by code.
Validators are functions. Built-in ones include Validators.required, minLength, min, max, email, and pattern. A control has valid, invalid, touched, dirty, and errors. A good habit is to show an error only after the field is touched, so the user is not shown red text before typing.
Typed forms (Angular 14 and newer) make control.value typed. fb.nonNullable.group({...}) gives string types instead of string | null, which helps with reset() as well.
Rule of thumb: a one or two field form can be template-driven. Anything with dynamic fields, cross-field rules, or serious testing needs should be reactive.
import { Component, inject } from '@angular/core';
import { FormBuilder, ReactiveFormsModule, Validators } from '@angular/forms';
@Component({
selector: 'app-signup',
imports: [ReactiveFormsModule],
template: `
<form [formGroup]="form" (ngSubmit)="submit()">
<label for="email">Email</label>
<input id="email" type="email" formControlName="email" />
@if (form.controls.email.touched && form.controls.email.errors; as errs) {
<small role="alert">
@if (errs['required']) { Email is required. }
@else if (errs['email']) { Enter a valid email. }
</small>
}
<label for="age">Age</label>
<input id="age" type="number" formControlName="age" />
<button type="submit" [disabled]="form.invalid">Join</button>
</form>
`,
})
export class SignupComponent {
private readonly fb = inject(FormBuilder);
readonly form = this.fb.nonNullable.group({
email: ['', [Validators.required, Validators.email]],
age: [18, [Validators.required, Validators.min(16), Validators.max(100)]],
});
submit(): void {
if (this.form.invalid) {
this.form.markAllAsTouched();
return;
}
const { email, age } = this.form.getRawValue();
console.log(`Registered ${email}, age ${age}`);
}
}Angular 20.3, strict template type-checking passes. The submit handler uses `getRawValue()` so it is also typed.
Key points
- Template-driven: model in the template, `ngModel`, `FormsModule`. Reactive: model in the class, `FormGroup`, `ReactiveFormsModule`.
- Validators are functions and set `errors` on the control.
- Show errors after `touched` or `dirty`, not on first render.
- `fb.nonNullable` gives non-null types in typed forms.
Common mistakes
- Importing `FormsModule` when the template uses `formGroup`. It needs `ReactiveFormsModule`.
- Mixing `ngModel` and `formControlName` on the same input.
- Checking `form.valid` once in the constructor instead of in the template or on submit.
Follow-ups
- How do you write a custom validator?
- What is the difference between `setValue` and `patchValue`?
- When does `updateOn: 'blur'` help?
Tips
- Give the practical rule for choosing between them instead of listing features.
- Mention that typed forms exist. It shows you are current.
- Always add accessible error messages next to the field, and say so.
Evaluation rubric
- Explains where each model lives.
- Builds a reactive form with validators and error display.
- Knows typed form basics.