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