Open History to see the last commit
1# TanStack Query Angular `toResource` with Signal Forms example
2β
3This example uses Angular Signal Forms' `validateAsync` with a Resource created
4from `injectQuery` and `toResource`. The username check is cached by its query
5key, debounced while typing, and cancelled when the value changes. The example
6also adds an invite-code field dynamically, giving it its own async validator,
7and includes a button that calls Signal Forms' `reloadValidation()` API. The
8invite-code validator is applied with `applyEach`, so its Resource factory is
9created only when an invite-code item is added to the form array. Query keys and
10request options live in `ValidationQueriesService`; the validators spread those
11options and add `enabled` based on the current field value.
12Submitting the form runs a mock `injectMutation`, disables the submit button while it is pending,
13and displays the variables passed to the mutation.
14β
15This example intentionally uses Angular 22 because Signal Forms' `validateAsync`
16API is stable starting in Angular 22.
17β
18The `debounce` option on `validateAsync` does not work with `toResource(query)`
19due to an [upstream Angular issue](https://github.com/angular/angular/issues/70884).
20Instead, the example uses `debounce(fieldPath, 300)` from `@angular/forms/signals`
21for the username and invite-code fields. This delays input updates to the form
22model; blurring a field or submitting the form flushes its pending update immediately.
23β
24To run this example:
25β
26- `pnpm install`
27- `pnpm start`