0
Fork 0
mirror of https://github.com/TanStack/query.git synced 2026-11-16 22:50:20 +00:00
query/examples/angular/auto-refetching
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 docs(angular-query): add auto-refetching example (#8371) 2024-12-05 00:30:59 +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 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): 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/angular): align 'angular.json', root components, 'OnPush', mock interceptors and 'tsconfig' across the examples (#12593) 2026-11-14 02:55:47 +09:00
tsconfig.app.json docs(angular-query): add auto-refetching example (#8371) 2024-12-05 00:30:59 +01: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 Auto Refetching Example

A todo list that polls the server with refetchInterval. Adding a todo or clearing the list invalidates the query.

How it works

  • src/app/services/tasks/queries.ts has two @Injectable classes: TasksQueries, whose list() returns queryOptions, and TasksMutations, whose create() and deleteAll() return mutationOptions. Both convert the HttpClient calls from src/app/services/tasks/api.ts with lastValueFrom.
  • src/app/components/auto-refetching.component.ts spreads list() into injectQuery with refetchInterval: this.intervalMs(), so changing the intervalMs signal from the input changes the polling rate. The template lights a dot while isFetching() is true.
  • In src/app/components/auto-refetching.component.ts, addMutation and clearMutation are created with injectMutation, and both invalidate the list's queryKey on success.
  • src/app/interceptor/tasks-mock.interceptor.ts is an HttpInterceptorFn, registered with withInterceptors in src/app/app.config.ts, that answers /api/tasks from localStorage after 100 ms for GET, POST and DELETE.

To run this example:

  • npm install
  • npm start