pickstack

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 --yes
Customize in the configurator

Packages it adds

PackageVersionType
@tanstack/angular-query^5.108.4runtime

New files

public/stack.json
["Angular 22", "TypeScript", "TanStack Query"]
src/app/api/stack.ts
/** 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();
}
src/app/components/stack-list/stack-list.html
<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>
src/app/components/stack-list/stack-list.ts
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

src/app/app.config.ts (changed)
⋯ 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)], };  
src/app/pages/about/about.html (changed)
 <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>  
src/app/pages/home/home.html (changed)
 <section class="page">   <h1 class="title">my-app</h1>   <app-counter />+  <app-stack-list /> </section>  
src/app/pages/home/home.ts (changed)
 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

Related templates