Installation
Install the Angular Form package:Basic Form Setup
The minimum setup requires creating a form instance withinjectForm and adding a field using the tanstackField directive.
import { Component } from '@angular/core'
import { TanStackField, injectForm } from '@tanstack/angular-form'
form = injectForm({
defaultValues: {
fullName: '',
},
onSubmit({ value }) {
// Do something with form data
console.log(value)
},
})
<ng-container
[tanstackField]="form"
name="fullName"
#fullName="field"
>
<label [for]="fullName.api.name">First Name:</label>
<input
[name]="fullName.api.name"
[value]="fullName.api.state.value"
(blur)="fullName.api.handleBlur()"
(input)="fullName.api.handleChange($any($event).target.value)"
/>
</ng-container>
Complete Example
Here’s a complete working example:Next Steps
Now that you have a basic form working, explore more features:- Learn about basic concepts like field state and reactivity
- Add validation to your forms
- Work with array fields for dynamic lists