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