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