0
Fork 0
mirror of https://github.com/TanStack/query.git synced 2026-11-16 22:50:20 +00:00
query/examples/angular/basic
History 2026-11-14 02:55:47 +09:00
..
.devcontainer chore(angular-query): update example dev containers to node 22 (#8370) 2024-11-28 17:24:46 +01:00
public docs(examples): use the TanStack Query emblem as the favicon in every example (#12578) 2026-11-12 13:33:29 +09:00
src docs(examples/angular): align 'angular.json', root components, 'OnPush', mock interceptors and 'tsconfig' across the examples (#12593) 2026-11-14 02:55:47 +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): use the TanStack Query emblem as the favicon in every example (#12578) 2026-11-12 13:33:29 +09:00
eslint.config.js chore(examples/*/eslint.config): use 'flat/recommended-strict' from '@tanstack/eslint-plugin-query' (#12385) 2026-10-26 02:55:51 +09:00
package.json ci: Version Packages (#12543) 2026-11-07 00:00:45 +01: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 ci: rename integration projects for consistency (#7875) 2024-08-09 20:09:09 +10:00
tsconfig.json chore(examples/*/tsconfig): include '*.config.ts' and '*.config.js' like the packages (#12408) 2026-10-27 09:11:08 +09:00

TanStack Angular Query Basic Example

A list of posts and a post detail view. Posts you have already opened are marked as visited from the query cache.

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 PostsQueries whose list() and detail(id) return queryOptions and turn the observables into promises with lastValueFrom. The detail request is stopped with takeUntil when the query's signal aborts.
  • src/app/components/posts.component.ts reads the list with injectQuery(() => this.postsQueries.list()), and src/app/components/posts.component.html shows a post in bold green when queryClient.getQueryData(postsQueries.detail(post.id).queryKey) returns data.
  • src/app/components/post.component.ts passes the postId input signal to injectQuery(() => this.#postsQueries.detail(this.postId())), so the query follows the selected post and shows "Background Updating..." while isFetching() is true.
  • src/app/app.config.ts registers the QueryClient with provideTanStackQuery and a default gcTime of 24 hours, plus withDevtools().

To run this example:

  • npm install
  • npm start