Open History to see the last commit
1---
2id: overview
3title: Overview
4---
5β
6> IMPORTANT: This library is currently in an experimental stage. This means that breaking changes will happen in minor AND patch releases. Upgrade carefully. If you use this in production while in experimental stage, please lock your version to a patch-level version to avoid unexpected breaking changes.
7β
8The `@tanstack/angular-query-experimental` package offers a 1st-class API for using TanStack Query via Angular.
9β
10## Feedback welcome!
11β
12We are in the process of getting to a stable API for TanStack Query on Angular. If you have any feedback, please contact us at the [TanStack Discord](https://tlinz.com/discord) server or [visit this discussion](https://github.com/TanStack/query/discussions/6293) on Github.
13β
14## Supported Angular Versions
15β
16TanStack Query is compatible with Angular v16 and higher.
17β
18TanStack Query (FKA React Query) is often described as the missing data-fetching library for web applications, but in more technical terms, it makes **fetching, caching, synchronizing and updating server state** in your web applications a breeze.
19β
20## Motivation
21β
22Most core web frameworks **do not** come with an opinionated way of fetching or updating data in a holistic way. Because of this developers end up building either meta-frameworks which encapsulate strict opinions about data-fetching, or they invent their own ways of fetching data. This usually means cobbling together component-based state and side-effects, or using more general purpose state management libraries to store and provide asynchronous data throughout their apps.
23β
24While most traditional state management libraries are great for working with client state, they are **not so great at working with async or server state**. This is because **server state is totally different**. For starters, server state:
25β
26- Is persisted remotely in a location you may not control or own
27- Requires asynchronous APIs for fetching and updating
28- Implies shared ownership and can be changed by other people without your knowledge
29- Can potentially become "out of date" in your applications if you're not careful
30β
31Once you grasp the nature of server state in your application, **even more challenges will arise** as you go, for example:
32β
33- Caching... (possibly the hardest thing to do in programming)
34- Deduping multiple requests for the same data into a single request
35- Updating "out of date" data in the background
36- Knowing when data is "out of date"
37- Reflecting updates to data as quickly as possible
38- Performance optimizations like pagination and lazy loading data
39- Managing memory and garbage collection of server state
40- Memoizing query results with structural sharing
41β
42If you're not overwhelmed by that list, then that must mean that you've probably solved all of your server state problems already and deserve an award. However, if you are like a vast majority of people, you either have yet to tackle all or most of these challenges and we're only scratching the surface!
43β
44TanStack Query is hands down one of the _best_ libraries for managing server state. It works amazingly well **out-of-the-box, with zero-config, and can be customized** to your liking as your application grows.
45β
46TanStack Query allows you to defeat and overcome the tricky challenges and hurdles of _server state_ and control your app data before it starts to control you.
47β
48On a more technical note, TanStack Query will likely:
49β
50- Help you remove **many** lines of complicated and misunderstood code from your application and replace with just a handful of lines of Angular Query logic.
51- Make your application more maintainable and easier to build new features without worrying about wiring up new server state data sources
52- Have a direct impact on your end-users by making your application feel faster and more responsive than ever before.
53- Potentially help you save on bandwidth and increase memory performance
54β
55[//]: # 'Example'
56β
57## Enough talk, show me some code already!
58β
59In the example below, you can see TanStack Query in its most basic and simple form being used to fetch the GitHub stats for the TanStack Query GitHub project itself:
60β
61[Open in StackBlitz](https://stackblitz.com/github/TanStack/query/tree/main/examples/angular/simple)
62β
63```angular-ts
64import { ChangeDetectionStrategy, Component, inject } from '@angular/core'
65import { HttpClient } from '@angular/common/http'
66import { CommonModule } from '@angular/common'
67import { injectQuery } from '@tanstack/angular-query-experimental'
68import { lastValueFrom } from 'rxjs'
69β
70@Component({
71 changeDetection: ChangeDetectionStrategy.OnPush,
72 selector: 'simple-example',
73 template: `
74 @if (query.isPending()) {
75 Loading...
76 }
77 @if (query.error()) {
78 An error has occurred: {{ query.error().message }}
79 }
80 @if (query.data(); as data) {
81 <h1>{{ data.name }}</h1>
82 <p>{{ data.description }}</p>
83 <strong>π {{ data.subscribers_count }}</strong>
84 <strong>β¨ {{ data.stargazers_count }}</strong>
85 <strong>π΄ {{ data.forks_count }}</strong>
86 }
87 `,
88})
89export class SimpleExampleComponent {
90 http = inject(HttpClient)
91β
92 query = injectQuery(() => ({
93 queryKey: ['repoData'],
94 queryFn: () =>
95 lastValueFrom(
96 this.http.get<Response>('https://api.github.com/repos/tanstack/query'),
97 ),
98 }))
99}
100β
101interface Response {
102 name: string
103 description: string
104 subscribers_count: number
105 stargazers_count: number
106 forks_count: number
107}
108```
109β
110## You talked me into it, so what now?
111β
112- Learn TanStack Query at your own pace with our amazingly thorough [Walkthrough Guide](./installation.md) and [API Reference](./reference/functions/injectQuery.md)