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:151](https://github.com/TanStack/query/blob/main/packages/angular-query-experimental/src/providers.ts#L151)
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β
51```ts
52import { provideTanStackQuery, QueryClient } from '@tanstack/angular-query-experimental'
53import { withDevtools } from '@tanstack/angular-query-devtools'
54β
55bootstrapApplication(AppComponent, {
56 providers: [...provideTanStackQuery(new QueryClient(), withDevtools())],
57})
58```
59β
60**Example: using an InjectionToken**
61β
62```ts
63export const MY_QUERY_CLIENT = new InjectionToken('', {
64 factory: () => new QueryClient(),
65})
66β
67// In a lazy loaded route or lazy loaded component's providers array:
68providers: [...provideTanStackQuery(MY_QUERY_CLIENT)]
69```
70Using an InjectionToken for the QueryClient is an advanced optimization which allows TanStack Query to be absent from the main application bundle.
71This can be beneficial if you want to include TanStack Query on lazy loaded routes only while still sharing a `QueryClient`.
72β
73Note that this is a small optimization and for most applications it's preferable to provide the `QueryClient` in the main application config.
74β
75## Parameters
76β
77### queryClient
78β
79A `QueryClient` instance, or an `InjectionToken` which provides a `QueryClient`.
80β
81`QueryClient` | `InjectionToken`\<`QueryClient`\>
82β
83### features
84β
85...[`QueryFeatures`](../type-aliases/QueryFeatures.md)[]
86β
87Optional features to configure additional Query functionality.
88β
89## Returns
90β
91`Provider`[]
92β
93A set of providers to set up TanStack Query (spread into `providers`).
94β
95## See
96β
97 - https://tanstack.com/query/v5/docs/framework/angular/quick-start
98 - https://tanstack.com/query/v5/docs/framework/angular/devtools
99 - https://tanstack.com/query/latest/docs/framework/angular/guides/ssr