Sub topic 16
Migrate from Reactive Forms
This chapter assumes you know Reactive Forms basics (FormGroup, FormControl, Validators) and the earlier chapters on form(), schema functions, and field state. Signal Forms is experimental in Angular 21, so check the release notes before you migrate a production form.
Plan an incremental migration
You do not need to rewrite an application at once. Both form systems can live in the same app, and each form is a separate unit. Migrate one form at a time, starting with small leaf forms such as login or search. Keep large forms, especially ones with many nested FormArrays, for last.
Map the concepts
The concepts translate one to one in most cases.
| Reactive Forms | Signal Forms |
|---|---|
| `FormGroup` of `FormControl`s | A `signal` model passed to `form()` |
| `formControlName`, `[formControl]` | `[field]` directive |
| `control.value` | `loginForm.email().value()` |
| `Validators.required`, `Validators.email` | `required()`, `email()` in the schema |
| Custom `ValidatorFn` | `validate()` |
| Group-level validator | `validate()` using `valueOf()` |
| `control.disable()` | `disabled()` rule |
| `markAllAsTouched()` then check `valid` | `submit()` |
| `FormArray` | Array in the model, with `applyEach` |
The main change is who owns the data. In Reactive Forms the form object holds the values. In Signal Forms your signal model holds them, and the form is a view over it.
A worked conversion
Here is a Reactive Forms version of a signup form.
import { FormBuilder, Validators } from '@angular/forms';
import { inject } from '@angular/core';
export class SignupBefore {
private readonly fb = inject(FormBuilder);
readonly form = this.fb.nonNullable.group({
email: ['', [Validators.required, Validators.email]],
password: ['', [Validators.required, Validators.minLength(8)]],
});
}Here is the same form as a signal model and a schema function.
import { signal } from '@angular/core';
import { form, required, email, minLength } from '@angular/forms/signals';
export class SignupAfter {
private readonly model = signal({ email: '', password: '' });
readonly signupForm = 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' });
minLength(path.password, 8, { message: 'Use at least 8 characters' });
});
}In the template, replace formControlName="email" with [field]="signupForm.email". Import Field in the component instead of ReactiveFormsModule, and remove the [formGroup] binding.
Common errors
- Reading values the old way.
signupForm.email.valuedoes not exist. Call the field first, then the signal:signupForm.email().value(). - Mixing both systems on one input. Do not put
formControlNameand[field]on the same element. Convert a whole form, or leave it alone. - Replacing
valueChangeswith a subscription. Usecomputed()oreffect()onvalue()instead. - Skipping the tests. Error messages, touched timing, and disabled behavior can differ slightly. Re-run your form tests after each conversion.
Exercise
A Reactive Forms group has a validator on the group that checks password equals confirm. Which Signal Forms function replaces it, and how does it read the other field?
Show answer
Use validate() on path.confirm. Inside it, call valueOf(path.password) to read the other field and compare it with value(). Return null when they match, or an error object such as { kind: 'mismatch', message: 'Passwords must match' } when they do not.