Prerequisites
Before installing Angular Query, ensure your project meets these requirements:- Angular 16+ - Angular Query uses signals and modern Angular features
- TypeScript 5.0+ - Required for full type inference
- Node.js 16+ - For package installation
Installation
The package name includes
-experimental because Angular Query is currently in experimental stage. This means breaking changes may occur in minor and patch releases.Angular Query requires a
QueryClient to manage your queries and mutations. You can configure it globally in your application. Standalone (Recommended)
For standalone Angular applications (Angular 14+), use
bootstrapApplication with providers:main.ts
NgModule
For NgModule-based applications, add the provider to your root module:
app.module.ts
import {
provideTanStackQuery,
QueryClient
} from '@tanstack/angular-query-experimental'
export const appConfig: ApplicationConfig = {
providers: [
provideTanStackQuery(
new QueryClient({
defaultOptions: {
queries: {
staleTime: 1000 * 60 * 5, // 5 minutes
gcTime: 1000 * 60 * 10, // 10 minutes (formerly cacheTime)
retry: 3,
refetchOnWindowFocus: true,
},
},
})
)
]
}
These default options apply to all queries and mutations in your application, but can be overridden on a per-query basis.
import {
provideTanStackQuery,
QueryClient,
withDevtools
} from '@tanstack/angular-query-experimental'
export const appConfig: ApplicationConfig = {
providers: [
provideTanStackQuery(
new QueryClient(),
withDevtools() // Enables devtools in development mode
)
]
}
The DevTools will automatically appear in development mode. See the DevTools documentation for more options.
Advanced Configuration
Using InjectionToken
For advanced use cases like lazy loading, you can provide theQueryClient using an InjectionToken:
query-client.ts
app.routes.ts
Using an
InjectionToken allows TanStack Query to be excluded from the main application bundle and only loaded with specific routes.Multiple QueryClient Instances
You can provide differentQueryClient instances for different parts of your application:
lazy-route.ts
Server-Side Rendering (SSR)
For Angular Universal applications, ensure theQueryClient is provided correctly:
app.config.server.ts
Verify Installation
Create a simple component to verify the installation:test.component.ts
Troubleshooting
Error: “No QueryClient found”
This error occurs whenprovideTanStackQuery is not in the provider tree. Ensure you’ve added it to your application config or module providers.
Error: “injectQuery must be called in an injection context”
Angular Query hooks must be called during component/service construction. See the injection context documentation for solutions.TypeScript Errors
Ensure you’re using TypeScript 5.0 or higher. Update yourtsconfig.json:
tsconfig.json
Next Steps
Quick Start
Build your first query
Queries Guide
Learn about queries in depth
DevTools
Set up debugging tools
API Reference
Explore the full API