mirror of
https://github.com/TanStack/query.git
synced 2026-11-16 22:50:20 +00:00
* chore(*): adopt '@tanstack/oxlint-config' and '@tanstack/oxfmt-config', and fix the newly reported lint errors * chore(pnpm-lock.yaml): run 'pnpm dedupe' * chore(scripts): move 'oxlint/plugin.ts' to 'oxlint-plugin.ts' to match the flat layout of 'scripts' * chore(pnpm-workspace.yaml): update '@typescript-eslint/parser' and '@typescript-eslint/rule-tester' to '^8.72.1' to match the deduped '@typescript-eslint/utils' |
History
|
|
|---|---|---|
| .. | ||
| .devcontainer | ||
| public | ||
| src | ||
| .gitignore | ||
| angular.json | ||
| eslint.config.js | ||
| package.json | ||
| README.md | ||
| tsconfig.app.json | ||
| tsconfig.json | ||
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.tsis an@InjectablePostsAPIthat returnsHttpClientobservables for the post list and a single post.src/app/services/posts/queries.tsis an@InjectablePostsQuerieswhoselist()anddetail(id)returnqueryOptionsand turn the observables into promises withlastValueFrom. The detail request is stopped withtakeUntilwhen the query'ssignalaborts.src/app/components/posts.component.tsreads the list withinjectQuery(() => this.postsQueries.list()), andsrc/app/components/posts.component.htmlshows a post in bold green whenqueryClient.getQueryData(postsQueries.detail(post.id).queryKey)returns data.src/app/components/post.component.tspasses thepostIdinput signal toinjectQuery(() => this.#postsQueries.detail(this.postId())), so the query follows the selected post and shows "Background Updating..." whileisFetching()istrue.src/app/app.config.tsregisters theQueryClientwithprovideTanStackQueryand a defaultgcTimeof 24 hours, pluswithDevtools().
To run this example:
npm installnpm start