Angular + TanStack Query
Server state: caching, refetching, loading and error states. This page shows exactly what pickstack adds to a Angular project for TanStack Query: 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-query --yesCustomize in the configurator
Packages it adds
| Package | Version | Type |
|---|---|---|
@tanstack/angular-query | ^5.108.4 | runtime |
New files
["Angular 22", "TypeScript", "TanStack Query"]
/** Loads the stack list served from `public/stack.json`. */
export async function fetchStack(): Promise<string[]> {
const response = await fetch("stack.json");
if (!response.ok) throw new Error(`Request failed: ${response.status}`);
return response.json();
}
<p class="text">
@if (stack.isPending()) {
Loading…
} @else if (stack.isError()) {
Could not load the stack.
} @else if (stack.data(); as data) {
Built with {{ data.join(", ") }}.
}
</p>
import { Component } from "@angular/core";
import { injectQuery } from "@tanstack/angular-query";
import { fetchStack } from "../../api/stack";
@Component({
selector: "app-stack-list",
templateUrl: "./stack-list.html",
})
export class StackList {
protected readonly stack = injectQuery(() => ({
queryKey: ["stack"],
queryFn: fetchStack,
}));
}
Changes to existing files
⋯ 2 unchanged lines provideBrowserGlobalErrorListeners, } from "@angular/core"; import { provideRouter } from "@angular/router";+import { provideTanStackQuery, QueryClient } from "@tanstack/angular-query"; import { routes } from "./app.routes"; export const appConfig: ApplicationConfig = {+ providers: [+ provideBrowserGlobalErrorListeners(),+ provideRouter(routes),+ provideTanStackQuery(() => new QueryClient()),+ ],− providers: [provideBrowserGlobalErrorListeners(), provideRouter(routes)], };
<section class="page"> <h1 class="title">About</h1>+ <p class="text">Built with Angular 22, TypeScript, TanStack Query.</p>− <p class="text">Built with Angular 22, TypeScript.</p> </section>
<section class="page"> <h1 class="title">my-app</h1> <app-counter />+ <app-stack-list /> </section>
import { Component } from "@angular/core"; import { Counter } from "../../components/counter/counter";+import { StackList } from "../../components/stack-list/stack-list"; @Component({ selector: "app-home",+ imports: [Counter, StackList],− imports: [Counter], templateUrl: "./home.html", }) export class Home {}⋯ 1 unchanged lines
Project files
.gitignoreREADME.mdangular.jsonpackage.jsonpublic/robots.txtpublic/stack.jsonsrc/app/api/stack.tssrc/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/stack-list/stack-list.htmlsrc/app/components/stack-list/stack-list.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