You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -138,26 +138,26 @@ Once we call a `FieldTree` as a function, we get a `FieldState` as the result.
138
138
## Connecting Fields to the Template
139
139
140
140
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.
142
142
To use the directive, we need to import it first.
143
143
In our example, we also import `JsonPipe` so we can use it in our template to display the current form value.
144
144
145
145
```typescript
146
146
import { JsonPipe } from'@angular/common';
147
-
import { /* ... */, Control } from'@angular/forms/signals';
147
+
import { /* ... */, Field } from'@angular/forms/signals';
148
148
// ...
149
149
@Component({
150
150
selector: 'app-registration-form',
151
-
imports: [Control, JsonPipe],
151
+
imports: [Field, JsonPipe],
152
152
templateUrl: './registration-form.html',
153
153
})
154
154
exportclassRegistrationForm {
155
155
// ...
156
156
}
157
157
```
158
158
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.
161
161
On the right side of the binding, we pass the corresponding `FieldTree` from our form structure.
162
162
163
163
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.
<labelfor="newsletter">Subscribe to newsletter</label>
180
180
<input
181
181
id="newsletter"
182
182
type="checkbox"
183
-
[control]="registrationForm.newsletter"
183
+
[field]="registrationForm.newsletter"
184
184
/>
185
185
</div>
186
186
@@ -193,7 +193,7 @@ We will handle validation later by using a form schema.
193
193
```
194
194
195
195
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.
197
197
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.
198
198
199
199
### Working with Arrays
@@ -214,7 +214,7 @@ The `registrationForm.email` field returns an array of `FieldTree` objects that
@@ -527,7 +527,7 @@ You can find a complete demo application for this blog series on GitHub and Stac
527
527
## What's Next?
528
528
529
529
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.
531
531
With schema-based validation, we can define all validation rules in a clear and reusable way.
532
532
533
533
In this first part, we've covered the fundamentals of Signal Forms:
0 commit comments