0
Fork 0
mirror of https://github.com/TanStack/query.git synced 2026-11-18 19:33:22 +00:00
query/packages/angular-query-experimental
Dominik Dorfmeister 🔮 279bb5508b
chore: update to ts 7 and move cut-off to 5.6 (#11212)
* update to ts 7 and move cut-off to 5.7

* changeset

* fix: use typescript v6 with tsup

* ci: apply automated fixes

* ref: update sveltejs/package

* ref: make ts6 the default typescript

* fix: lit build

* effing tsup

* move ignoreDeprecations to solid tsup config

* move ignoreDeprecations to relevant tsup configs

* better lit fix

* restore vue queryClient

* Revert "restore vue queryClient"

This reverts commit 4f95fc918a.

* fix things

* ignore devDep ordering

* vue needs to use ts6

---------

Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
History 2026-08-17 22:50:18 +02:00
..
scripts refactor(angular-query): restructure package type declaration path (#9519) 2025-08-01 14:11:54 +02:00
src chore: update to ts 7 and move cut-off to 5.6 (#11212) 2026-08-17 22:50:18 +02:00
.attw.json refactor(angular-query): build with vite, publish d.ts files to package root (#9292) 2025-06-21 00:02:17 +02:00
CHANGELOG.md ci: Version Packages (#11094) 2026-07-21 15:00:30 +02:00
eslint.config.js chore(angular-query): remove jsdoc eslint rules (#9803) 2025-10-23 15:50:27 +02:00
package.json chore: update to ts 7 and move cut-off to 5.6 (#11212) 2026-08-17 22:50:18 +02:00
README.md docs: use the dynamic README header endpoint (#11136) 2026-08-03 13:43:19 +02:00
root.eslint.config.js chore: composite monorepo (#8560) 2025-01-27 15:58:10 +01:00
test-setup.ts test(angular-query-experimental/injectQueries): switch to fake timers, replace 'setTimeout' with 'sleep', replace 'findByText' with 'getByText', add 'toBeInTheDocument', remove unused 'toString' method, rename '_pushResults' to '_', and add '@testing-library/jest-dom/vitest' (#9896) 2026-03-18 15:22:03 +01:00
tsconfig.json chore(tsconfig.json): narrow 'include' pattern to prevent TS6053 race conditions from tsup bundled config files (#10522) 2026-05-04 03:24:13 +09:00
tsconfig.prod.json fix(build): exclude config files from production DTS rollup (#10358) 2026-04-01 09:40:46 +02:00
vite.config.ts fix(tests): disable local coverage instrumentation (#10776) 2026-05-26 17:29:33 +02:00

TanStack Angular Query

npm version npm license bundle size npm

Angular Query

IMPORTANT: This library is currently in an experimental stage. This means that breaking changes may happen in minor AND patch releases. Upgrade carefully. If you use this in production while in experimental stage, please lock your version to a patch-level version to avoid unexpected breaking changes.

Functions for fetching, caching and updating asynchronous data in Angular

Documentation

Visit https://tanstack.com/query/latest/docs/framework/angular/overview

Quick Features

  • Transport/protocol/backend agnostic data fetching (REST, GraphQL, promises, whatever!)
  • Auto Caching + Refetching (stale-while-revalidate, Window Refocus, Polling/Realtime)
  • Parallel + Dependent Queries
  • Mutations + Reactive Query Refetching
  • Multi-layer Cache + Automatic Garbage Collection
  • Paginated + Cursor-based Queries
  • Load-More + Infinite Scroll Queries w/ Scroll Recovery
  • Request Cancellation
  • Dedicated Devtools

Quick Start

The Angular adapter for TanStack Query requires Angular 16 or higher.

  1. Install angular-query
$ npm i @tanstack/angular-query-experimental

or

$ pnpm add @tanstack/angular-query-experimental

or

$ yarn add @tanstack/angular-query-experimental

or

$ bun add @tanstack/angular-query-experimental
  1. Initialize TanStack Query by adding provideTanStackQuery to your application
import { provideTanStackQuery } from '@tanstack/angular-query-experimental'
import { QueryClient } from '@tanstack/angular-query-experimental'

bootstrapApplication(AppComponent, {
  providers: [provideTanStackQuery(new QueryClient())],
})

or in a NgModule-based app

import { provideHttpClient } from '@angular/common/http'
import {
  provideTanStackQuery,
  QueryClient,
} from '@tanstack/angular-query-experimental'

@NgModule({
  declarations: [AppComponent],
  imports: [BrowserModule],
  providers: [provideTanStackQuery(new QueryClient())],
  bootstrap: [AppComponent],
})
  1. Inject query
import { injectQuery } from '@tanstack/angular-query-experimental'
import { Component } from '@angular/core'

@Component({...})
export class TodosComponent {
  info = injectQuery(() => ({ queryKey: ['todos'], queryFn: fetchTodoList }))
}
  1. If you need to update options on your query dynamically, make sure to pass them as signals. The query will refetch automatically if data for an updated query key is stale or not present.

Open in StackBlitz

@Component({})
export class PostComponent {
  #postsService = inject(PostsService)
  postId = input.required({
    transform: numberAttribute,
  })

  postQuery = injectQuery(() => ({
    queryKey: ['post', this.postId()],
    queryFn: () => {
      return lastValueFrom(this.#postsService.postById$(this.postId()))
    },
  }))
}

@Injectable({
  providedIn: 'root',
})
export class PostsService {
  #http = inject(HttpClient)

  postById$ = (postId: number) =>
    this.#http.get<Post>(`https://jsonplaceholder.typicode.com/posts/${postId}`)
}

export interface Post {
  id: number
  title: string
  body: string
}