Signal Forms
Angular Signal Forms (introduced in Angular 21 and stabilized in Angular 22 under @angular/forms/signals) provide a model-first, type-safe alternative to Reactive Forms. Instead of wrapping data inside separate FormGroup and FormControl classes, your plain TypeScript data stored inside a writable signal() serves as the single source of truth
Core Architecture & Concepts
- Data Model Signal (
signal<T>()). You start with a standard writable signal holding a typed interface. Updating this signal automatically updates the UI, and typing in the UI updates the signal. form()& theFieldTree. Passing your model signal toform(model, schemaFn)generates a strongly typedFieldTreethat mirrors the exact shape of your data. AccessingmyForm.email()returns aFieldStateobject containing reactive signals like.value(),.valid(),.invalid(),.touched(),.dirty(), and.errors().- Declarative Schema Validation. Instead of attaching validator arrays to individual controls, you pass a schema callback to
form(). Functions likerequired(),email(),minLength(),debounce(), anddisabled()apply rules using type-safe field paths. [formField]Directive. A single directive binds both native HTML inputs and custom components directly to aFieldTreenode (e.g.,[formField]="loginForm.email").- Custom Controls Without
ControlValueAccessor. Custom form components simply implementFormValueControl<T>with avalue = model<T>()signal, eliminatingNG_VALUE_ACCESSORproviders and callback boilerplate.
Signal Forms vs. Reactive Forms
| Feature | Reactive Forms (Legacy) | Signal Forms (Angular 22+) |
|---|---|---|
| Source of Truth | Duplicated between FormGroup internal state and your domain data model. |
Your writable signal<T>() model directly. |
| Type Safety | form.get('nested.field') uses string paths and defaults controls to T | null. |
Full compile-time dot notation (form.nested.field) with exact model types. |
| Dynamic Rules | Imperative .disable(), .setValidators(), and valueChanges subscriptions. |
Reactive schema rules (applyWhen(), disabled(), hidden()) that re-evaluate automatically. |
| Custom Controls | ControlValueAccessor + NG_VALUE_ACCESSOR + forwardRef boilerplate. |
Single value = model() property via FormValueControl<T>. |
1. Main Registration Form Component
import { Component, signal } from '@angular/core';
import { email, form, FormField, minLength, required } from '@angular/forms/signals';
interface LoginData {
email: string;
password: string;
}
@Component({
selector: 'app-login-form',
imports: [FormField, BasicInput, RatingPickerComponent],
template: `
<form (submit)="onSubmit($event)">
@if (loginForm.email().touched() && loginForm.email().invalid()) {
@for (error of loginForm.email().errors(); track error) {
<p>{{ error.message }}</p>
}
}
@if (loginForm.password().touched() && loginForm.password().invalid()) {
@for (error of loginForm.password().errors(); track error) {
<p>{{ error.message }}</p>
}
}
<label>
Email:
<input type="email" [formField]="loginForm.email" />
</label>
<label>
Password:
<input type="password" [formField]="loginForm.password" />
</label>
<p>Hello {{ loginForm.email().value() }}</p>
<p>Password {{ loginForm.password().value().length }}</p>
<input type="submit" value="Submit" />
</form>
`,
})
export class LoginFormComponent {
loginModel = signal<LoginData>({
email: '',
password: ''
});
loginForm = form(this.loginModel, (schemaPath) => {
required(schemaPath.email, { message: 'Email is required' });
email(schemaPath.email, { message: 'Enter a valid email address' });
required(schemaPath.password, { message: 'Password is required' });
minLength(schemaPath.password, 8, { message: 'Password must be minimum 8 chars' });
});
onSubmit(event: Event) {
event.preventDefault();
const credentials = this.loginModel();
console.log('Logging in with:', credentials);
}
}
2. Custom Form Control (FormValueControl)
Custom components can implement FormValueControl<T> rather than traditional ControlValueAccessor boilerplate, exposing a value = model<T>() signal directly bound via [formField]:
import { Component, model, output } from '@angular/core';
import { FormValueControl } from '@angular/forms/signals';
@Component({
selector: 'app-rating-picker',
template: `
<div class="stars">
@for (star of [1, 2, 3, 4, 5]; track star) {
<button
type="button"
[class.selected]="star <= value()"
(click)="selectRating(star)"
>
★
</button>
}
</div>
`,
})
export class RatingPickerComponent implements FormValueControl<number> {
value = model<number>(0);
touch = output<void>();
selectRating(rating: number) {
this.value.set(rating);
this.touch.emit();
}
}
<label>
Rating
<app-rating-picker [formField]="feedbackForm.rating"></app-rating-picker>
</label>
References
- https://angularexperts.io/blog/angular-signal-forms-custom-controls/
- https://medium.com/@raj1996kamal/understanding-signal-forms-in-angular-e890c0d29817
- https://medium.com/@vetriselvan_11/angular-signal-forms-replacing-controlvalueaccessor-with-formvaluecontrol-3329f6272c8f
- https://www.youtube.com/watch?v=CEAVN_pkCXU&vl=en&t=832
- https://www.youtube.com/watch?v=fZZ1UVkyB4I&vl=en&t=84
- https://www.youtube.com/watch?v=Iq7apYJtPtI&vl=en&t=144
- https://www.youtube.com/watch?v=J0pVA4lJMso&t=174