Angular + TanStack Form
Type-safe forms with Zod or Yup validation. This page shows exactly what pickstack adds to a Angular project for TanStack Form: the packages, the new files and the changes to existing ones. Every combination is installed, built, linted and tested in CI.
$ npm create pickstack@latest my-app -- --framework angular --modules tanstack-form --yesCustomize in the configurator
Packages it adds
| Package | Version | Type |
|---|---|---|
@tanstack/angular-form | ^1.33.5 | runtime |
zod | ^4.6.7 | runtime |
New files
@if (joined()) {
<p class="text">Thanks, {{ joined() }} is on the list.</p>
} @else {
<form novalidate class="form" (submit)="submit($event)">
<ng-container [tanstackField]="form" name="email" #email="field">
<label class="field">
Email
<input
type="email"
class="input"
[name]="email.api.name"
[value]="email.api.state.value"
(blur)="email.api.handleBlur()"
(input)="email.api.handleChange($any($event.target).value)"
/>
@if (errors()[0]; as error) {
<span role="alert" class="error">{{ error.message }}</span>
}
</label>
</ng-container>
<button type="submit" class="btn">Sign up</button>
</form>
}
import { Component, signal } from "@angular/core";
import { injectForm, injectStore, TanStackField } from "@tanstack/angular-form";
import { z } from "zod";
const schema = z.object({
email: z.email("Enter a valid email address."),
});
@Component({
selector: "app-signup-form",
imports: [TanStackField],
templateUrl: "./signup-form.html",
})
export class SignupForm {
protected readonly joined = signal("");
protected readonly form = injectForm({
defaultValues: { email: "" },
validators: { onSubmit: schema },
onSubmit: ({ value }) => this.joined.set(value.email),
});
// The template reads errors through a signal, so it updates without zone.js.
protected readonly errors = injectStore(
this.form,
(state) => state.fieldMeta.email?.errors ?? [],
);
protected submit(event: SubmitEvent): void {
event.preventDefault();
void this.form.handleSubmit();
}
}
Changes to existing files
<section class="page"> <h1 class="title">About</h1>+ <p class="text">Built with Angular 22, TypeScript, TanStack Form, Zod.</p>− <p class="text">Built with Angular 22, TypeScript.</p> </section>
<section class="page"> <h1 class="title">my-app</h1> <app-counter />+ <app-signup-form /> </section>
import { Component } from "@angular/core"; import { Counter } from "../../components/counter/counter";+import { SignupForm } from "../../components/signup-form/signup-form"; @Component({ selector: "app-home",+ imports: [Counter, SignupForm],− imports: [Counter], templateUrl: "./home.html", }) export class Home {}⋯ 1 unchanged lines
⋯ 87 unchanged lines background: #334155; } +.form {+ display: flex;+ width: 100%;+ max-width: 24rem;+ flex-direction: column;+ gap: 0.75rem;+}+ +.field {+ display: flex;+ flex-direction: column;+ gap: 0.25rem;+ font-size: 0.875rem;+ font-weight: 500;+}+ +.input {+ border: 1px solid #cbd5e1;+ border-radius: 0.5rem;+ padding: 0.5rem 0.75rem;+ font: inherit;+}+ +.error {+ color: #dc2626;+ font-weight: 400;+}+
Project files
.gitignoreREADME.mdangular.jsonpackage.jsonpublic/robots.txtsrc/app/app.config.tssrc/app/app.htmlsrc/app/app.routes.tssrc/app/app.tssrc/app/components/counter/counter.htmlsrc/app/components/counter/counter.tssrc/app/components/signup-form/signup-form.htmlsrc/app/components/signup-form/signup-form.tssrc/app/pages/about/about.htmlsrc/app/pages/about/about.tssrc/app/pages/home/home.htmlsrc/app/pages/home/home.tssrc/index.htmlsrc/main.tssrc/styles.csstsconfig.app.jsontsconfig.json