Open History to see the last commit
1# TanStack Angular Query Basic Example (Angular Router)
2β
3The basic posts example with Angular Router, one route per view.
4β
5Built with [Angular Router](https://angular.dev/guide/routing).
6β
7## How it works
8β
9- `src/app/services/posts/api.ts` is an `@Injectable` `PostsAPI` that returns `HttpClient` observables for the post list and a single post.
10- `src/app/services/posts/queries.ts` is an `@Injectable({ providedIn: 'root' })` class, `PostsQueries`, whose `list()` and `detail(id)` return `queryOptions` and convert the observables with `lastValueFrom`. Components get it with `inject(PostsQueries)`.
11- `src/app/components/posts.component.ts` reads the list with `injectQuery(() => this.postsQueries.list())`, and `src/app/components/posts.component.html` links each post with `routerLink` and shows it in bold green when `queryClient.getQueryData(postsQueries.detail(post.id).queryKey)` returns data.
12- `src/app/components/post.component.ts` receives the `postId` route param as an input through `withComponentInputBinding` and passes it to `injectQuery(() => this.#postsQueries.detail(this.postId()))`.
13- `src/app/app.routes.ts` lazy loads both components with `loadComponent`, and `src/app/app.config.ts` sets up `provideRouter` and `provideTanStackQuery` with `withDevtools()`.
14β
15To run this example:
16β
17- `npm install`
18- `npm start`