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