Skip to content

Commit e78a458

Browse files
committed
signalforms: rename input [field] to [fieldRef]
1 parent 0626288 commit e78a458

File tree

2 files changed

+15
-11
lines changed

2 files changed

+15
-11
lines changed

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

Lines changed: 9 additions & 5 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-15
6+
lastModified: 2025-10-16
77
keywords:
88
- Angular
99
- Signals
@@ -479,7 +479,7 @@ To make the error display reusable, we can create a dedicated component for it:
479479
The component can receive any `FieldTree` and checks for its errors when the field is already marked as touched.
480480
It displays all errors related to the field by iterating over the `errors()` signal.
481481

482-
To get access to the `FieldState`, we have to call the `field` property twice: Once to get the `FieldTree` from the input signal, and a second time to get the `FieldState` with its reactive properties.
482+
To get access to the `FieldState`, we have to call the `fieldRef` property twice: Once to get the `FieldTree` from the input signal, and a second time to get the `FieldState` with its reactive properties.
483483

484484
```typescript
485485
import { Component, input } from '@angular/core';
@@ -488,7 +488,7 @@ import { ValidationError, WithOptionalField } from '@angular/forms/signals';
488488
@Component({
489489
selector: 'app-form-error',
490490
template: `
491-
@let state = field()();
491+
@let state = fieldRef()();
492492
@if (state.touched() && state.errors().length) {
493493
<ul>
494494
@for (error of state.errors(); track $index) {
@@ -499,7 +499,7 @@ import { ValidationError, WithOptionalField } from '@angular/forms/signals';
499499
`,
500500
})
501501
export class FormError<T> {
502-
readonly field = input.required<FieldTree<T>>();
502+
readonly fieldRef = input.required<FieldTree<T>>();
503503
}
504504
```
505505

@@ -509,10 +509,14 @@ Now we can use this component in our form and pass any field to it.
509509
<label>
510510
Username
511511
<input type="text" [field]="registrationForm.username" />
512-
<app-form-error [field]="registrationForm.username" />
512+
<app-form-error [fieldRef]="registrationForm.username" />
513513
</label>
514514
```
515515

516+
We intentionally named the input `fieldRef` to avoid confusion with the `Field` directive.
517+
Whenever we use the `[field]` binding, it applies the directive to a form element.
518+
Since `<app-form-error>` is just a helper component, we cannot use the same name for the input property.
519+
516520

517521
## Demo
518522

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ In our template, we can now use a `[ariaInvalid]` binding on the input elements
6464
[field]="registrationForm.username"
6565
[ariaInvalid]="ariaInvalidState(registrationForm.username)"
6666
/>
67-
<app-form-error [field]="registrationForm.username" />
67+
<app-form-error [fieldRef]="registrationForm.username" />
6868
</label>
6969
```
7070

@@ -115,7 +115,7 @@ The validation messages will be displayed in the UI since we included our generi
115115
/>
116116
<button type="button" (click)="removeEmail($index)">-</button>
117117
</div>
118-
<app-form-error [field]="emailField" />
118+
<app-form-error [fieldRef]="emailField" />
119119
</div>
120120
}
121121
</div>
@@ -169,7 +169,7 @@ To display the error message, we add our `FormError` component below the `@for`
169169
<!-- ... -->
170170
}
171171
</div>
172-
<app-form-error [field]="registrationForm.email" />
172+
<app-form-error [fieldRef]="registrationForm.email" />
173173
</fieldset>
174174
<!-- ... -->
175175
```
@@ -207,7 +207,7 @@ Errors can be assigned to individual fields (`pw1`) or to the grouping node (`pa
207207
[field]="registrationForm.password.pw1"
208208
[ariaInvalid]="ariaInvalidState(registrationForm.password.pw1)"
209209
/>
210-
<app-form-error [field]="registrationForm.password.pw1" />
210+
<app-form-error [fieldRef]="registrationForm.password.pw1" />
211211
</label>
212212
<label
213213
>Password Confirmation
@@ -217,9 +217,9 @@ Errors can be assigned to individual fields (`pw1`) or to the grouping node (`pa
217217
[field]="registrationForm.password.pw2"
218218
[ariaInvalid]="ariaInvalidState(registrationForm.password.pw2)"
219219
/>
220-
<app-form-error [field]="registrationForm.password.pw2" />
220+
<app-form-error [fieldRef]="registrationForm.password.pw2" />
221221
</label>
222-
<app-form-error [field]="registrationForm.password" />
222+
<app-form-error [fieldRef]="registrationForm.password" />
223223
```
224224

225225
For validations that depend on multiple fields, Signal Forms provide a `validateTree()` function.

0 commit comments

Comments
 (0)