Skip to content

Commit 0626288

Browse files
committed
signalforms: rename [control] to [field]
1 parent d614dff commit 0626288

File tree

2 files changed

+19
-19
lines changed

2 files changed

+19
-19
lines changed

blog/2025-10-signal-forms-part1/README.md

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ title: "Angular Signal Forms Part 1: Getting Started with the Basics"
33
author: Danny Koppenhagen and Ferdinand Malcher
44
mail: [email protected] # Gravatar
55
published: 2025-10-13
6-
lastModified: 2025-10-13
6+
lastModified: 2025-10-15
77
keywords:
88
- Angular
99
- Signals
@@ -138,26 +138,26 @@ Once we call a `FieldTree` as a function, we get a `FieldState` as the result.
138138
## Connecting Fields to the Template
139139

140140
Now that we have our form structure in place, we need to connect it to our HTML template to create functional input fields with reactive data binding.
141-
Signal Forms use the `Control` directive to bind form fields to HTML input elements.
141+
Signal Forms use the `Field` directive to bind form fields to HTML input elements.
142142
To use the directive, we need to import it first.
143143
In our example, we also import `JsonPipe` so we can use it in our template to display the current form value.
144144

145145
```typescript
146146
import { JsonPipe } from '@angular/common';
147-
import { /* ... */, Control } from '@angular/forms/signals';
147+
import { /* ... */, Field } from '@angular/forms/signals';
148148
// ...
149149
@Component({
150150
selector: 'app-registration-form',
151-
imports: [Control, JsonPipe],
151+
imports: [Field, JsonPipe],
152152
templateUrl: './registration-form.html',
153153
})
154154
export class RegistrationForm {
155155
// ...
156156
}
157157
```
158158

159-
The `Control` directive works directly with all standard HTML form elements like `<input>`, `<textarea>`, and `<select>`.
160-
Let's start with a basic template that connects some of our form fields: We apply the directive to the HTML element by using the `[control]` property binding.
159+
The `Field` directive works directly with all standard HTML form elements like `<input>`, `<textarea>`, and `<select>`.
160+
Let's start with a basic template that connects some of our form fields: We apply the directive to the HTML element by using the `[field]` property binding.
161161
On the right side of the binding, we pass the corresponding `FieldTree` from our form structure.
162162

163163
Notice, that we also use the form attribute `novalidate`: It disables the native browser field validation.
@@ -167,20 +167,20 @@ We will handle validation later by using a form schema.
167167
<form (submit)="submitForm($event)" novalidate>
168168
<div>
169169
<label for="username">Username</label>
170-
<input id="username" type="text" [control]="registrationForm.username" />
170+
<input id="username" type="text" [field]="registrationForm.username" />
171171
</div>
172172

173173
<div>
174174
<label for="age">Age</label>
175-
<input id="age" type="number" [control]="registrationForm.age" />
175+
<input id="age" type="number" [field]="registrationForm.age" />
176176
</div>
177177

178178
<div>
179179
<label for="newsletter">Subscribe to newsletter</label>
180180
<input
181181
id="newsletter"
182182
type="checkbox"
183-
[control]="registrationForm.newsletter"
183+
[field]="registrationForm.newsletter"
184184
/>
185185
</div>
186186

@@ -193,7 +193,7 @@ We will handle validation later by using a form schema.
193193
```
194194

195195
We have now connected each input to its corresponding field in our form structure.
196-
The `Control` directive handles the two-way data binding automatically, keeping our data model synchronized with user input.
196+
The `Field` directive handles the two-way data binding automatically, keeping our data model synchronized with user input.
197197
The form model automatically synchronizes with the data signal: To read the value, we can use the signal as well as the `FieldState` with its `value` property.
198198

199199
### Working with Arrays
@@ -214,7 +214,7 @@ The `registrationForm.email` field returns an array of `FieldTree` objects that
214214
<div role="group">
215215
<input
216216
type="email"
217-
[control]="emailField"
217+
[field]="emailField"
218218
[ariaLabel]="'E-Mail ' + $index"
219219
/>
220220
<button type="button" (click)="removeEmail($index)">-</button>
@@ -508,7 +508,7 @@ Now we can use this component in our form and pass any field to it.
508508
```html
509509
<label>
510510
Username
511-
<input type="text" [control]="registrationForm.username" />
511+
<input type="text" [field]="registrationForm.username" />
512512
<app-form-error [field]="registrationForm.username" />
513513
</label>
514514
```
@@ -527,7 +527,7 @@ You can find a complete demo application for this blog series on GitHub and Stac
527527
## What's Next?
528528

529529
Signal Forms provide a modern and powerful way to handle forms in Angular applications.
530-
Getting started is straightforward and simple: Create a signal, derive the form structure and connect it to the template using the `Control` directive.
530+
Getting started is straightforward and simple: Create a signal, derive the form structure and connect it to the template using the `Field` directive.
531531
With schema-based validation, we can define all validation rules in a clear and reusable way.
532532

533533
In this first part, we've covered the fundamentals of Signal Forms:

blog/2025-10-signal-forms-part2/README.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ In our template, we can now use a `[ariaInvalid]` binding on the input elements
6161
>Username
6262
<input
6363
type="text"
64-
[control]="registrationForm.username"
64+
[field]="registrationForm.username"
6565
[ariaInvalid]="ariaInvalidState(registrationForm.username)"
6666
/>
6767
<app-form-error [field]="registrationForm.username" />
@@ -109,7 +109,7 @@ The validation messages will be displayed in the UI since we included our generi
109109
<div role="group">
110110
<input
111111
type="email"
112-
[control]="emailField"
112+
[field]="emailField"
113113
[ariaLabel]="'E-Mail ' + $index"
114114
[ariaInvalid]="ariaInvalidState(emailField)"
115115
/>
@@ -204,7 +204,7 @@ Errors can be assigned to individual fields (`pw1`) or to the grouping node (`pa
204204
<input
205205
type="password"
206206
autocomplete
207-
[control]="registrationForm.password.pw1"
207+
[field]="registrationForm.password.pw1"
208208
[ariaInvalid]="ariaInvalidState(registrationForm.password.pw1)"
209209
/>
210210
<app-form-error [field]="registrationForm.password.pw1" />
@@ -214,7 +214,7 @@ Errors can be assigned to individual fields (`pw1`) or to the grouping node (`pa
214214
<input
215215
type="password"
216216
autocomplete
217-
[control]="registrationForm.password.pw2"
217+
[field]="registrationForm.password.pw2"
218218
[ariaInvalid]="ariaInvalidState(registrationForm.password.pw2)"
219219
/>
220220
<app-form-error [field]="registrationForm.password.pw2" />
@@ -392,7 +392,7 @@ We can use this state to provide user feedback in the UI:
392392
<!-- ... -->
393393
<input
394394
type="text"
395-
[control]="registrationForm.username"
395+
[field]="registrationForm.username"
396396
[ariaInvalid]="ariaInvalidState(registrationForm.username)"
397397
/>
398398
@if (registrationForm.username().pending()) {
@@ -430,7 +430,7 @@ readonly(fieldPath.someField, (ctx) => !ctx.fieldOf(fieldPath.otherField)().vali
430430
hidden(fieldPath.someField, (ctx) => !ctx.valueOf(fieldPath.otherField));
431431
```
432432

433-
Disabled and read-only states are automatically reflected in the template when using the `[control]` directive.
433+
Disabled and read-only states are automatically reflected in the template when using the `[field]` directive.
434434
However, Angular cannot automatically hide fields in the template.
435435
Instead, it marks the fields as *hidden*, which we can use in our template to conditionally render the fields using `@if`.
436436

0 commit comments

Comments
 (0)