Open History to see the last commit
1---
2id: provideTanStackQuery
3title: provideTanStackQuery
4---
5β
6<!-- DO NOT EDIT: this page is autogenerated from the type comments -->
7β
8# Function: provideTanStackQuery()
9β
10```ts
11function provideTanStackQuery(queryClient, ...features): Provider[]
12```
13β
14Defined in: [providers.ts:105](https://github.com/TanStack/query/blob/main/packages/angular-query-experimental/src/providers.ts#L105)
15β
16Sets up providers necessary to enable TanStack Query functionality for Angular applications.
17β
18Allows to configure a `QueryClient` and optional features such as developer tools.
19β
20**Example - standalone**
21β
22```ts
23import {
24 provideTanStackQuery,
25 QueryClient,
26} from '@tanstack/angular-query-experimental'
27β
28bootstrapApplication(AppComponent, {
29 providers: [provideTanStackQuery(new QueryClient())],
30})
31```
32β
33**Example - NgModule-based**
34β
35```ts
36import {
37 provideTanStackQuery,
38 QueryClient,
39} from '@tanstack/angular-query-experimental'
40β
41@NgModule({
42 declarations: [AppComponent],
43 imports: [BrowserModule],
44 providers: [provideTanStackQuery(new QueryClient())],
45 bootstrap: [AppComponent],
46})
47export class AppModule {}
48```
49β
50You can also enable optional developer tools by adding `withDevtools`. By
51default the tools will then be loaded when your app is in development mode.
52β
53```ts
54import {
55 provideTanStackQuery,
56 withDevtools
57 QueryClient,
58} from '@tanstack/angular-query-experimental'
59β
60bootstrapApplication(AppComponent,
61 {
62 providers: [
63 provideTanStackQuery(new QueryClient(), withDevtools())
64 ]
65 }
66)
67```
68β
69**Example: using an InjectionToken**
70β
71```ts
72export const MY_QUERY_CLIENT = new InjectionToken('', {
73 factory: () => new QueryClient(),
74})
75β
76// In a lazy loaded route or lazy loaded component's providers array:
77providers: [provideTanStackQuery(MY_QUERY_CLIENT)]
78```
79β
80Using an InjectionToken for the QueryClient is an advanced optimization which allows TanStack Query to be absent from the main application bundle.
81This can be beneficial if you want to include TanStack Query on lazy loaded routes only while still sharing a `QueryClient`.
82β
83Note that this is a small optimization and for most applications it's preferable to provide the `QueryClient` in the main application config.
84β
85## Parameters
86β
87### queryClient
88β
89A `QueryClient` instance, or an `InjectionToken` which provides a `QueryClient`.
90β
91`QueryClient` | `InjectionToken`\<`QueryClient`\>
92β
93### features
94β
95...[`QueryFeatures`](../../type-aliases/queryfeatures.md)[]
96β
97Optional features to configure additional Query functionality.
98β
99## Returns
100β
101`Provider`[]
102β
103A set of providers to set up TanStack Query.
104β
105## See
106β
107- https://tanstack.com/query/v5/docs/framework/angular/quick-start
108- withDevtools