0
Fork 0
mirror of https://github.com/TanStack/query.git synced 2026-11-16 22:50:20 +00:00
query/examples/angular/basic-persister
Wonsuk Choi cb62f4f2ed
chore(*): adopt '@tanstack/oxlint-config' and '@tanstack/oxfmt-config', and fix the newly reported lint errors (#12555)
* 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 2026-11-16 22:25:25 +09:00
..
.devcontainer feat(angular-query): add angular-persist-query-client 2025-04-13 19:42:49 +02: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 chore(*): adopt '@tanstack/oxlint-config' and '@tanstack/oxfmt-config', and fix the newly reported lint errors (#12555) 2026-11-16 22:25:25 +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/angular): align 'angular.json', root components, 'OnPush', mock interceptors and 'tsconfig' across the examples (#12593) 2026-11-14 02:55:47 +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 feat(angular-query): add angular-persist-query-client 2025-04-13 19:42:49 +02:00
tsconfig.json 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

TanStack Angular Query Basic Persister Example

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

How it works

  • src/app/services/posts/queries.ts is an @Injectable PostsQueries whose list() and detail(id) return queryOptions and turn the HttpClient observables from src/app/services/posts/api.ts into promises with lastValueFrom.
  • 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.
  • src/app/app.config.ts adds withPersistQueryClient to provideTanStackQuery with a localStorage persister from createAsyncStoragePersister. The QueryClient sets a default staleTime of 1 minute and a gcTime of 24 hours, and the persisted cache is restored when the page reloads.

To run this example:

  • npm install
  • npm start