Open History to see the last commit
1
2β
3[](https://www.npmjs.com/package/@tanstack/angular-query-experimental)
4[](https://github.com/TanStack/query/blob/main/LICENSE)
5[](https://bundlephobia.com/package/@tanstack/angular-query-experimental)
6[](https://www.npmjs.com/package/@tanstack/angular-query-experimental)
7β
8# Angular Query
9β
10> IMPORTANT: This library is currently in an experimental stage. This means that breaking changes will 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.
11β
12Functions for fetching, caching and updating asynchronous data in Angular
13β
14# Documentation
15β
16Visit https://tanstack.com/query/latest/docs/framework/angular/overview
17β
18## Quick Features
19β
20- Transport/protocol/backend agnostic data fetching (REST, GraphQL, promises, whatever!)
21- Auto Caching + Refetching (stale-while-revalidate, Window Refocus, Polling/Realtime)
22- Parallel + Dependent Queries
23- Mutations + Reactive Query Refetching
24- Multi-layer Cache + Automatic Garbage Collection
25- Paginated + Cursor-based Queries
26- Load-More + Infinite Scroll Queries w/ Scroll Recovery
27- Request Cancellation
28- Dedicated Devtools
29β
30# Quick Start
31β
32> Angular Query requires Angular 16.
33β
341. Install `angular-query`
35β
36 ```bash
37 $ npm i @tanstack/angular-query-experimental
38 ```
39β
40 or
41β
42 ```bash
43 $ pnpm add @tanstack/angular-query-experimental
44 ```
45β
46 or
47β
48 ```bash
49 $ yarn add @tanstack/angular-query-experimental
50 ```
51β
52 or
53β
54 ```bash
55 $ bun add @tanstack/angular-query-experimental
56 ```
57β
582. Initialize **Angular Query** by adding **provideAngularQuery** to your application
59β
60 ```ts
61 import { provideAngularQuery } from '@tanstack/angular-query-experimental'
62 import { QueryClient } from '@tanstack/angular-query-experimental'
63β
64 bootstrapApplication(AppComponent, {
65 providers: [provideAngularQuery(new QueryClient())],
66 })
67 ```
68β
69 or in a NgModule-based app
70β
71 ```ts
72 import { provideHttpClient } from '@angular/common/http'
73 import {
74 provideAngularQuery,
75 QueryClient,
76 } from '@tanstack/angular-query-experimental'
77β
78 @NgModule({
79 declarations: [AppComponent],
80 imports: [BrowserModule],
81 providers: [provideAngularQuery(new QueryClient())],
82 bootstrap: [AppComponent],
83 })
84 ```
85β
863. Inject query
87β
88 ```ts
89 import { injectQuery } from '@tanstack/angular-query-experimental'
90 import { Component } from '@angular/core'
91β
92 @Component({...})
93 export class TodosComponent {
94 info = injectQuery(() => ({ queryKey: ['todos'], queryFn: fetchTodoList }))
95 }
96 ```
97β
984. If you need to update options on your query dynamically, make sure to pass them as signals
99β
100 ```ts
101 import { injectQuery } from '@tanstack/angular-query-experimental'
102 import { signal, Component } from '@angular/core'
103β
104 @Component({...})
105 export class TodosComponent {
106 id = signal(1)
107 enabled = signal(false)
108β
109 info = injectQuery(() => ({
110 queryKey: ['todos', this.id()],
111 queryFn: fetchTodoList,
112 enabled: this.enabled(),
113 }))
114 }
115 ```