0
Fork 0
mirror of https://github.com/TanStack/query.git synced 2026-11-16 22:50:20 +00:00
query/examples/angular/basic-angular-router
History 2026-11-13 10:57:29 +09:00
..
.devcontainer docs(examples): rewrite the READMEs, add the framework or router to example titles, and rename examples to '<feature>-<framework>' (#12583) 2026-11-12 16:58:15 +09:00
public docs(examples): rewrite the READMEs, add the framework or router to example titles, and rename examples to '<feature>-<framework>' (#12583) 2026-11-12 16:58:15 +09:00
src docs(examples): rewrite the READMEs, add the framework or router to example titles, and rename examples to '<feature>-<framework>' (#12583) 2026-11-12 16:58:15 +09:00
.gitignore docs(examples): use each framework's template '.gitignore' in every example (#12592) 2026-11-13 10:57:29 +09:00
angular.json docs(examples): rewrite the READMEs, add the framework or router to example titles, and rename examples to '<feature>-<framework>' (#12583) 2026-11-12 16:58:15 +09:00
eslint.config.js docs(examples): rewrite the READMEs, add the framework or router to example titles, and rename examples to '<feature>-<framework>' (#12583) 2026-11-12 16:58:15 +09:00
package.json docs(examples): rewrite the READMEs, add the framework or router to example titles, and rename examples to '<feature>-<framework>' (#12583) 2026-11-12 16:58:15 +09:00
README.md docs(examples): rewrite the READMEs, add the framework or router to example titles, and rename examples to '<feature>-<framework>' (#12583) 2026-11-12 16:58:15 +09:00
tsconfig.app.json docs(examples): rewrite the READMEs, add the framework or router to example titles, and rename examples to '<feature>-<framework>' (#12583) 2026-11-12 16:58:15 +09:00
tsconfig.json docs(examples): rewrite the READMEs, add the framework or router to example titles, and rename examples to '<feature>-<framework>' (#12583) 2026-11-12 16:58:15 +09:00

TanStack Angular Query Basic Example (Angular Router)

The basic posts example with Angular Router, one route per view.

Built with Angular Router.

How it works

  • src/app/services/posts/api.ts is an @Injectable PostsAPI that returns HttpClient observables for the post list and a single post.
  • 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).
  • 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.
  • 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())).
  • src/app/app.routes.ts lazy loads both components with loadComponent, and src/app/app.config.ts sets up provideRouter and provideTanStackQuery with withDevtools().

To run this example:

  • npm install
  • npm start