mirror of
https://github.com/TanStack/query.git
synced 2026-11-16 22:50:20 +00:00
* docs(examples): describe each example in its README with a summary, the framework it is built with, how it works and the npm commands * docs(examples): add the framework or router to the README heading and page title of examples that have variants * docs(examples/react): rename the Next.js examples to '<feature>-nextjs-<pages|app>-router' * docs(examples/react): update package names, docs links and labels, and the lockfile for the renamed Next.js examples * docs(examples): rename 'svelte/sveltekit', 'solid/solid-start-streaming' and 'angular/router' to '<feature>-<framework>' * docs(examples): correct README details on staleness, hydration, 'hasMore', streaming and dependent queries, and prefetch on 'focusin' in 'vue/prefetching-nuxt4' |
History
|
|
|---|---|---|
| .. | ||
| .devcontainer | ||
| public | ||
| src | ||
| 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