Sub topic 1
Why Signal Forms and how it differs from Reactive Forms
Signal Forms is Angular's signal-based forms API. You import it from @angular/forms/signals. It was introduced as experimental in Angular 21, so names and details can change between releases. This chapter explains what problem it solves, how its model differs from Reactive Forms and Template-driven forms, and which mistakes to avoid early. Later chapters cover each piece in detail.
Prerequisites
This chapter assumes you already know:
- TypeScript fundamentals, including generics and object types.
- Angular standalone components and templates, including
@ifand@for. - Angular signals:
signal(),computed(), andeffect(). - Basic HTML form elements and validation ideas such as required fields and email format.
- Reactive Forms or Template-driven forms. This is helpful but not required. The comparisons below are written so you can follow them without it.
The problem with existing forms
Angular has two older form systems.
- Template-driven forms use
ngModelin the template. They are quick to write, but validation logic ends up spread across the template, and the form is hard to test. - Reactive Forms build the form in code with
FormControl,FormGroup, andFormArray. They are explicit and testable, and most production Angular code uses them.
Reactive Forms predate signals. A FormControl stores its own copy of the value, and you observe changes through RxJS streams such as valueChanges and statusChanges. This causes friction in a signal-based app:
- Your component state lives in signals, but the form state lives in a separate object tree. You must keep the two in sync by hand, usually with
valueChanges.subscribe(...)ortoSignal(). - Reading validity or errors in a template means calling properties such as
control.invalidandcontrol.errors. These are plain getters, not signals, socomputed()andeffect()do not track them reliably. - The form shape is declared separately from the data type. You write an interface for the data and then a parallel group of controls.
- Validators are attached to individual controls, so a rule that involves two fields lives on the parent group.
Signal Forms addresses these points by making the data itself a signal and deriving the form from it.
The core idea: the model is the form
In Signal Forms, you start with a writable signal that holds your data. This is the model. You pass it to form(), which returns a structure of fields that mirrors the model's shape. The model remains the single source of truth. The form does not keep a separate copy of the values.
import { signal } from '@angular/core';
import { form, required, email } from '@angular/forms/signals';
const model = signal({ email: '', password: '' });
const loginForm = form(model, (path) => {
required(path.email, { message: 'Email is required' });
email(path.email, { message: 'Enter a valid email address' });
required(path.password, { message: 'Password is required' });
});Three things to notice:
- The type of the form comes from the model. There is no second declaration of the shape.
- The second argument is a schema function. It receives a
pathobject that mirrors the model, and you declare validation rules against its properties. - Calling a field gives you its state.
loginForm.email()returns the state of the email field, andloginForm.email().value(),.touched(),.invalid(), and.errors()are all signals.
Because the model is a signal, model() always returns the current data. Because the field state is made of signals, you can use it directly in computed(), effect(), and templates.
The same form in both styles
Here is a login form with Reactive Forms.
import { Component } from '@angular/core';
import { FormControl, FormGroup, ReactiveFormsModule, Validators } from '@angular/forms';
@Component({
selector: 'app-login-reactive',
imports: [ReactiveFormsModule],
template: `
<form [formGroup]="loginForm" (ngSubmit)="onSubmit()">
<input type="email" formControlName="email" />
@if (loginForm.controls.email.touched && loginForm.controls.email.invalid) {
<p class="error">Enter a valid email address</p>
}
<input type="password" formControlName="password" />
<button type="submit" [disabled]="loginForm.invalid">Log in</button>
</form>
`,
})
export class LoginReactiveComponent {
protected readonly loginForm = new FormGroup({
email: new FormControl('', { nonNullable: true, validators: [Validators.required, Validators.email] }),
password: new FormControl('', { nonNullable: true, validators: [Validators.required] }),
});
protected onSubmit() {
console.log(this.loginForm.getRawValue());
}
}Here is the Signal Forms version of the same screen.
import { Component, signal } from '@angular/core';
import { form, Field, required, email } from '@angular/forms/signals';
@Component({
selector: 'app-login',
imports: [Field],
template: `
<form (submit)="onSubmit($event)">
<label>Email <input type="email" [field]="loginForm.email" /></label>
@if (loginForm.email().touched() && loginForm.email().invalid()) {
@for (error of loginForm.email().errors(); track error.kind) {
<p class="error">{{ error.message }}</p>
}
}
<label>Password <input type="password" [field]="loginForm.password" /></label>
<button type="submit" [disabled]="loginForm().invalid()">Log in</button>
</form>
`,
})
export class LoginComponent {
private readonly model = signal({ email: '', password: '' });
protected readonly loginForm = form(this.model, (path) => {
required(path.email, { message: 'Email is required' });
email(path.email, { message: 'Enter a valid email address' });
required(path.password, { message: 'Password is required' });
});
protected onSubmit(event: Event) {
event.preventDefault();
console.log(this.model());
}
}The binding is [field]="loginForm.email", provided by the Field directive. It replaces formControlName, formControl, and ngModel. The directive reads and writes the model through the field, so you do not need ReactiveFormsModule or FormsModule.
Side-by-side differences
| Aspect | Template-driven | Reactive Forms | Signal Forms |
|---|---|---|---|
| Source of truth | Component property bound with `ngModel` | Value stored inside each `FormControl` | A writable signal you own |
| Form shape | Implied by the template | Built manually with `FormGroup` and `FormArray` | Derived from the model's type |
| State reactivity | Change detection | Observables (`valueChanges`, `statusChanges`) | Signals |
| Validation location | Directives in the template | Validator functions on controls and groups | A schema function passed to `form()` |
| Template binding | `[(ngModel)]` | `formControlName`, `[formControl]` | `[field]` |
| Import path | `@angular/forms` | `@angular/forms` | `@angular/forms/signals` |
| Stability in Angular 21 | Stable | Stable | Experimental |
How data flows
When a user types, the Field directive writes the new value through the field into the model signal. Anything that reads the model, a field's value, or a field's validity is then updated through normal signal tracking. Validators in the schema function run as derived computations of the model, so no manual subscription is involved.
The practical result is that you can derive anything from the form with plain signal code. For example, computed(() => this.model().email.trim().length > 0) needs no subscription and no cleanup.
Common errors and gotchas
- Mixing the two systems on one input. Do not put
[field]andformControlNameon the same element. Pick one system per control. Migration chapters later in this tutorial cover how to run both in one app. - Forgetting that fields are functions.
loginForm.emailis the field.loginForm.email()is its state. WritingloginForm.email.invalid()is a mistake. You needloginForm.email().invalid(). The form as a whole follows the same rule:loginForm().invalid(). - Forgetting to import
Field. If the[field]binding does nothing or the compiler rejects it, check thatFieldis in the component'simportsarray. - Treating the model as a snapshot. The model is the live source of truth. Reading
this.model()insidecomputed()or a template tracks it. Copying it into another variable at construction time does not. - Writing validation rules outside the schema function. Rules such as
required()andemail()are called inside the function passed toform(), against thepathargument. Calling them elsewhere will not attach them to the form. - Relying on API names staying fixed. The
[field]directive andFieldclass are the names in the Angular 21 release. The experimental API may rename them later, so pin your Angular version and check the release notes when you upgrade.
When to choose which
Choose Signal Forms for new components in an application that already uses signals for state, especially when form values feed computed values or effects. Stay with Reactive Forms when you have a large existing codebase of controls, custom ControlValueAccessor components, or libraries that expect AbstractControl. Both can coexist in one application, so you can move incrementally.
Exercise
A teammate writes [disabled]="loginForm.invalid()" on a submit button, and the template fails to behave as expected. The form was created with const loginForm = form(model, ...). What is wrong, and what is the correct expression?
Show answer
loginForm is a field tree, and the state is exposed by calling the field. The correct expression is loginForm().invalid(). The first call returns the form's state, and invalid() is the signal on that state. Per-field state works the same way: loginForm.email().invalid().
Exercise
Name two reasons Signal Forms fits an application built on signals better than Reactive Forms does.
Show answer
The model is a signal you own, so there is no separate copy of the data to keep in sync. Field state such as value, validity, and errors is exposed as signals, so computed() and effect() track it without valueChanges subscriptions. The form's type is also derived from the model, so you do not declare the shape twice.