Skip to content
Source
Sign inSign up
TanStack/query
Open History to see the last commit

provideTanStackQuery.md

95 lines2.7 KB

1---
2id: provideTanStackQuery
3title: provideTanStackQuery
4---
5​
6# Function: provideTanStackQuery()
7​
8```ts
9function provideTanStackQuery(queryClient, ...features): EnvironmentProviders;
10```
11​
12Defined in: [providers.ts:124](https://github.com/TanStack/query/blob/main/packages/angular-query-experimental/src/providers.ts#L124)
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. SSR dehydration and client hydration are built in (see the [SSR guide](../../guides/ssr.md)); you do not need a separate hydration feature.
17​
18**Environment injector only:** use this with `bootstrapApplication`, `ApplicationConfig`, `NgModule.providers`, `mergeApplicationConfig`, or route-level providers. Do **not** use it in [`@Component({ providers })`](https://angular.dev/api/core/Component#providers).
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` from `@tanstack/angular-query-devtools` (see the [Angular Devtools guide](../../devtools.md)).
51​
52```ts
53import { provideTanStackQuery, QueryClient } from '@tanstack/angular-query-experimental'
54import { withDevtools } from '@tanstack/angular-query-devtools'
55​
56bootstrapApplication(AppComponent, {
57 providers: [provideTanStackQuery(new QueryClient(), withDevtools())],
58})
59```
60​
61**Example: using an InjectionToken**
62​
63```ts
64export const MY_QUERY_CLIENT = new InjectionToken('', {
65 factory: () => new QueryClient(),
66})
67​
68providers: [provideTanStackQuery(MY_QUERY_CLIENT)]
69```
70​
71## Parameters
72​
73### queryClient
74​
75A `QueryClient` instance, or an `InjectionToken` which provides a `QueryClient`.
76​
77`QueryClient` | `InjectionToken`\<`QueryClient`\>
78​
79### features
80​
81...[`QueryFeatures`](../type-aliases/QueryFeatures.md)[]
82​
83Optional features to configure additional Query functionality.
84​
85## Returns
86​
87`EnvironmentProviders`
88​
89A single value to place in environment `providers` (do not spread).
90​
91## See
92​
93 - https://tanstack.com/query/v5/docs/framework/angular/quick-start
94 - https://tanstack.com/query/v5/docs/framework/angular/devtools
95 - https://tanstack.com/query/latest/docs/framework/angular/guides/ssr