Current email: {{ loginForm.email().value() }}
``` Each field exposes: - `value()` - `valid()` - `errors()` - `dirty()` - `touched()` All as signals. --- ### 4. Updating Form Models Programmatically Signal Forms allow three update methods. #### 1. Replace the entire model ```ts this.userModel.set({ name: 'Alice', email: 'alice@example.com', }); ``` #### 2. Patch specific fields ```ts this.userModel.update(prev => ({ ...prev, email: newEmail, })); ``` #### 3. Update a single field ```ts this.userForm.email().value.set(''); ``` This eliminates the need for: - `patchValue()` - `setValue()` - `formGroup.get('field')` --- ### 5. Automatic Two-Way Binding With `[field]` The `[field]` directive enables perfect two-way data binding: ```html ``` #### How it works: - **User input → Field state → Model** - **Model updates → Field state → Input UI** No subscriptions. No event handlers. No boilerplate. Reactive Forms could never achieve this cleanly. --- ### 6. Nested Models and Arrays Models can contain nested object structures: ```ts userModel = signal({ name: '', address: { street: '', city: '', }, }); ``` Access fields easily: ```html ``` Arrays are also supported: ```ts orderModel = signal({ items: [ { product: '', quantity: 1, price: 0 } ] }); ``` Field state persists even when array items move, thanks to identity tracking. --- ### 7. Schema-Based Validation Validation is clean and centralized: ```ts import { required, email } from '@angular/forms/signals'; const model = signal({ email: '' }); const formRef = form(model, { email: [required(), email()], }); ``` Field validation state is reactive: ```ts formRef.email().valid() formRef.email().errors() formRef.email().touched() ``` Validation no longer scatters across components. --- ### 8. When Should You Use Signal Forms? #### New Angular 21+ apps Signal-first architecture is the new standard. #### Teams wanting stronger type safety Every field is exactly typed. #### Devs tired of Reactive Form boilerplate Signal Forms drastically simplify code. #### Complex UI with computed reactive form state Signals integrate perfectly. #### ❌ Avoid if: - You need long-term stability - You rely on mature Reactive Forms features - Your app must avoid experimental APIs --- ### 9. Reactive Forms vs Signal Forms | Feature | Reactive Forms | Signal Forms | |--------|----------------|--------------| | Boilerplate | High | Very low | | Type-safety | Weak | Strong | | Two-way binding | Manual | Automatic | | Validation | Scattered | Centralized schema | | Nested forms | Verbose | Natural | | Subscriptions | Required | None | | Change detection | Zone-heavy | Fine-grained | Signal Forms feel like the "modern Angular mode," while Reactive Forms increasingly feel legacy. --- ### 10. Full Example: Login Form ```ts @Component({ selector: 'app-login', imports: [Field], template: ` `, }) export class LoginComponent { model = signal({ email: '', password: '' }); form = form(this.model); submit() { console.log(this.model()); } } ``` Minimal. Reactive. Completely type-safe. --- ## **Conclusion** Signal Forms in Angular 21 represent a big step forward: - Cleaner API - Stronger type safety - Automatic two-way binding - Centralized validation - Fine-grained reactivity - Dramatically better developer experience Although these are experimental, they clearly show the future of Angular's form ecosystem. Once you get into using Signal Forms, you may never want to use Reactive Forms again. ---