function provideTanStackQuery(queryClientFactory: () => QueryClient, ...features: readonly QueryFeature[]): EnvironmentProviders;Defined in: packages/angular-query/src/providers.ts:126
Sets up providers necessary to enable TanStack Query functionality for Angular applications. Provides a QueryClient and optional TanStack Query features. The factory runs once per injector in Angular's injection context, so it can call inject() and each SSR request can receive an independent cache.
() => QueryClient
Creates or resolves a QueryClient in the injection context.
...readonly QueryFeature[]
Optional features to configure additional Query functionality.
EnvironmentProviders
A single EnvironmentProviders value (do not spread into providers).
import {
provideTanStackQuery,
QueryClient,
} from '@tanstack/angular-query'
bootstrapApplication(AppComponent, {
providers: [provideTanStackQuery(() => new QueryClient())],
})The same, in an NgModule-based application:
import { provideTanStackQuery, QueryClient } from '@tanstack/angular-query'
@NgModule({
declarations: [AppComponent],
imports: [BrowserModule],
providers: [provideTanStackQuery(() => new QueryClient())],
bootstrap: [AppComponent],
})
export class AppModule {}Enabling optional developer tools by adding withDevtools — by default, the tools are then loaded when your app is in development mode:
import { provideTanStackQuery, QueryClient } from '@tanstack/angular-query'
import { withDevtools } from '@tanstack/angular-query-devtools'
bootstrapApplication(AppComponent, {
providers: [
provideTanStackQuery(() => new QueryClient(), withDevtools()),
],
})Resolving the QueryClient from an InjectionToken — an advanced optimization that lets TanStack Query be absent from the main application bundle, useful for including it on lazy-loaded routes only while still sharing a QueryClient. This is a small optimization; for most applications it's preferable to provide the QueryClient in the main application config, as in the examples above:
export const MY_QUERY_CLIENT = new InjectionToken('', {
factory: () => new QueryClient(),
})
// In a lazy loaded route's providers array:
providers: [provideTanStackQuery(() => inject(MY_QUERY_CLIENT))]