# Introduction

> Typed multi-step flows for Angular, with signals, from one definition.

Framework: Angular (`@stepperize/angular`), Stepperize v9.
Source: https://stepperize.com/docs/v9/angular

Stepperize is for flows where someone moves through named steps: checkout,
onboarding, surveys, import wizards, approval flows and multi-step forms.

You describe the steps once. The definition gives you a signals API for your
components and services, and a set of accessible, unstyled directives for your
own templates.

```ts
import { Component } from "@angular/core";
import { defineStepper } from "@stepperize/angular";
import { z } from "zod";

const checkout = defineStepper([
  { id: "shipping", title: "Shipping", schema: z.object({ address: z.string().min(1) }) },
  { id: "payment", title: "Payment", schema: z.object({ card: z.string().length(16) }) },
  { id: "review", title: "Review" },
]);

@Component({
  selector: "app-checkout",
  template: `
    <h2>{{ stepper().current.title }}</h2>

    @switch (stepper().current.id) {
      @case ("shipping") { <app-shipping-form /> }
      @case ("payment") { <app-payment-form /> }
      @case ("review") { <app-review [data]="stepper().data" /> }
    }

    <button type="button" [disabled]="stepper().isFirst" (click)="stepper().prev()">Back</button>
    <button type="button" (click)="stepper().next(readForm())">
      {{ stepper().isLast ? "Place order" : "Continue" }}
    </button>
  `,
})
export class Checkout {
  readonly stepper = checkout.injectStepper({ onFinish: (output) => placeOrder(output) });
}
```

A flow built with the primitives, running:

The live demo runs in the browser. Its source ([mount/angular.ts](https://github.com/damianricobelli/stepperize/blob/main/apps/docs/src/components/framework-demos/mount/angular.ts)):

```ts
// The docs are not an Angular application, so there is no Angular compiler in the build: the
// demo loads the JIT compiler and declares its component with the function form of `Component`.
// In an application this is an ordinary `@Component` class, and with a `StepperRegistry`
// (see the primitives guide) the template type-checker checks every step id it names.
import "@angular/compiler";
import { ChangeDetectionStrategy, Component } from "@angular/core";
import { bootstrapApplication } from "@angular/platform-browser";
import { defineStepper, STEPPER_PRIMITIVES } from "@stepperize/angular";

const demo = defineStepper([
	{ id: "account", title: "Account", description: "Who you are" },
	{ id: "plan", title: "Plan", description: "What you need" },
	{ id: "done", title: "Done", description: "All set" },
]);

const TAG = "stepperize-angular-demo";
const panel = "rounded-md bg-fd-muted p-3";

const AngularDemo = Component({
	selector: TAG,
	imports: [STEPPER_PRIMITIVES],
	changeDetection: ChangeDetectionStrategy.OnPush,
	template: `
		<div
			[stepperRoot]="stepper"
			data-demo="angular"
			class="not-prose my-4 flex flex-col gap-4 rounded-lg border p-4 text-sm"
		>
			<ol stepperList class="flex gap-2">
				@for (step of stepper.steps; track step.id) {
					<li [stepperItem]="step" #item="stepperItem" class="flex-1">
						<button
							stepperTrigger
							class="flex w-full items-center gap-2 rounded-md border px-3 py-2 text-left data-[state=current]:border-fd-primary data-[state=current]:bg-fd-accent"
						>
							<span
								stepperIndicator
								class="flex size-6 shrink-0 items-center justify-center rounded-full border text-xs data-[state=complete]:bg-fd-primary data-[state=complete]:text-fd-primary-foreground"
								>{{ item.value().state === "complete" ? "✓" : item.value().index + 1 }}</span
							>
							<span class="flex flex-col">
								<span class="font-medium">{{ step.title }}</span>
								<span class="text-xs text-fd-muted-foreground">{{ item.value().step.description }}</span>
							</span>
						</button>
					</li>
				}
			</ol>
			<div stepperContent="account" class="${panel}">Create your account.</div>
			<div stepperContent="plan" class="${panel}">Pick the plan that fits.</div>
			<div stepperContent="done" class="${panel}" #done="stepperContent">
				@if (done.active()) {
					{{ stepper().isFinished ? "Finished. Thanks!" : "Press Finish to complete the flow." }}
				}
			</div>
			<div class="flex items-center gap-2">
				<button stepperPrev class="rounded-md border px-3 py-1 disabled:opacity-40">Back</button>
				<button stepperNext class="rounded-md border px-3 py-1 aria-disabled:opacity-40">
					{{ stepper().isLast ? "Finish" : "Continue" }}
				</button>
				<span data-step class="ml-auto text-xs text-fd-muted-foreground">
					Step {{ stepper().index + 1 }} of {{ stepper().steps.length }}
				</span>
			</div>
		</div>
	`,
})(
	class {
		readonly stepper = demo.injectStepper();
	},
);

export function mount(el: HTMLElement) {
	// `bootstrapApplication` renders into the first element that matches the selector.
	const host = document.createElement(TAG);
	el.appendChild(host);
	const application = bootstrapApplication(AngularDemo);
	return () => {
		void application.then((ref) => ref.destroy());
		host.remove();
	};
}
```

## Is it a form library?

No. Stepperize owns the **flow**: which step is current, moving between steps,
what each step saved and which steps are complete. Angular's forms own the
fields. See [Forms](https://stepperize.com/docs/v9/angular/guides/forms).

## What you get

- **One call moves forward.** `next(data)` saves the step's data, validates it
  against the step's schema and moves on. It resolves with what happened
  instead of throwing.
- **Signals.** The stepper is a signal: templates, `computed` and `effect`
  follow it, with no subscription to manage.
- **Typed.** Step ids, each step's data and your own fields (`title`, `icon`,
  anything) are inferred from the definition, in TypeScript and in template
  expressions. Register a definition and the step ids you give the directives
  are checked too.
- **Branching as data.** A `next` map decides where each step leads from its
  validated data, and a flow can have more than one ending.
- **Resumable.** One `snapshot` goes in, one `onChange` comes out. The current
  step can follow the router with a single option.
- **Accessible primitives.** Standalone directives handle roles, keyboard
  navigation, focus and announcements.
- **Zoneless and server rendered.** No zone.js needed; the server HTML already
  has the roles, and hydration adopts it.
- **Small.** About 3.2 KiB for the signals API and 8.7 KiB with the primitives,
  min + gzip, with no runtime dependencies besides the core.

## The same flow as every other binding

The state machine is [`@stepperize/core`](https://stepperize.com/docs/v9/core), shared by every
binding, so the concepts are the same everywhere. Each has its own page,
with Angular code: [steps](https://stepperize.com/docs/v9/angular/concepts/steps),
[the lifecycle of a move](https://stepperize.com/docs/v9/angular/concepts/moves),
[step state](https://stepperize.com/docs/v9/angular/concepts/step-state),
[validation](https://stepperize.com/docs/v9/angular/guides/validation),
[branching](https://stepperize.com/docs/v9/angular/guides/branching) and
[persistence](https://stepperize.com/docs/v9/angular/guides/persistence).

## Next

- [Installation](https://stepperize.com/docs/v9/angular/installation): Add the package to an Angular 22 project.

- [Your first stepper](https://stepperize.com/docs/v9/angular/first-stepper): A working flow, built in four small steps.

- [Primitives](https://stepperize.com/docs/v9/angular/guides/primitives): Accessible directives for your own templates.

- [Without Angular](https://stepperize.com/docs/v9/core): The same state machine in tests, servers and agents.
