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