@tanstack/angular-query-experimental

中文文档
5.105.2发布于 2026/11/02MITTypeScriptES Module构建来源已验证

Signals for managing, caching and syncing asynchronous and remote data in Angular

原始使用文档
TanStack Angular Query

npm version npm license bundle size npm

Angular Query

IMPORTANT: This library is currently in an experimental stage. This means that breaking changes may 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.

Functions for fetching, caching and updating asynchronous data in Angular

Documentation

Visit https://tanstack.com/query/latest/docs/framework/angular/overview

Quick Features

  • Transport/protocol/backend agnostic data fetching (REST, GraphQL, promises, whatever!)
  • Auto Caching + Refetching (stale-while-revalidate, Window Refocus, Polling/Realtime)
  • Parallel + Dependent Queries
  • Mutations + Reactive Query Refetching
  • Multi-layer Cache + Automatic Garbage Collection
  • Paginated + Cursor-based Queries
  • Load-More + Infinite Scroll Queries w/ Scroll Recovery
  • Request Cancellation
  • Dedicated Devtools

Quick Start

The Angular adapter for TanStack Query requires Angular 16 or higher.

  1. Install angular-query
$ npm i @tanstack/angular-query-experimental

or

$ pnpm add @tanstack/angular-query-experimental

or

$ yarn add @tanstack/angular-query-experimental

or

$ bun add @tanstack/angular-query-experimental
  1. Initialize TanStack Query by adding provideTanStackQuery to your application
import { provideTanStackQuery } from '@tanstack/angular-query-experimental'
import { QueryClient } from '@tanstack/angular-query-experimental'

bootstrapApplication(AppComponent, {
  providers: [provideTanStackQuery(new QueryClient())],
})

or in a NgModule-based app

import { provideHttpClient } from '@angular/common/http'
import {
  provideTanStackQuery,
  QueryClient,
} from '@tanstack/angular-query-experimental'

@NgModule({
  declarations: [AppComponent],
  imports: [BrowserModule],
  providers: [provideTanStackQuery(new QueryClient())],
  bootstrap: [AppComponent],
})
  1. Inject query
import { injectQuery } from '@tanstack/angular-query-experimental'
import { Component } from '@angular/core'

@Component({...})
export class TodosComponent {
  info = injectQuery(() => ({ queryKey: ['todos'], queryFn: fetchTodoList }))
}
  1. If you need to update options on your query dynamically, make sure to pass them as signals. The query will refetch automatically if data for an updated query key is stale or not present.

Open in StackBlitz

@Component({})
export class PostComponent {
  #postsService = inject(PostsService)
  postId = input.required({
    transform: numberAttribute,
  })

  postQuery = injectQuery(() => ({
    queryKey: ['post', this.postId()],
    queryFn: () => {
      return lastValueFrom(this.#postsService.postById$(this.postId()))
    },
  }))
}

@Injectable({
  providedIn: 'root',
})
export class PostsService {
  #http = inject(HttpClient)

  postById$ = (postId: number) =>
    this.#http.get<Post>(`https://jsonplaceholder.typicode.com/posts/${postId}`)
}

export interface Post {
  id: number
  title: string
  body: string
}

版本与发布记录

@tanstack/angular-query-experimental 共发布 333 个版本,首次发布于 2023/12/01;过去 12 个月发布了 74 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
5.105.2latest2026/11/02今天
5.105.12026/11/012 天前
5.105.02026/10/268 天前
5.104.52026/10/2014 天前
5.104.42026/10/1816 天前
5.104.32026/10/1519 天前

关于 @tanstack/angular-query-experimental 的常见问题

@tanstack/angular-query-experimental 是什么?

用于管理、缓存和同步Angular中的异步和远程数据的信号

如何安装 @tanstack/angular-query-experimental?

在项目目录运行 npm install @tanstack/angular-query-experimental,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:@angular/core(>=16.0.0)、@angular/common(>=16.0.0)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@tanstack/angular-query-experimental 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@tanstack/angular-query-experimental 支持 ESM 还是 CommonJS?

以 ES Module 形式发布,推荐使用 import 引入。在 CommonJS 项目中,Node.js 20.19+ / 22.12+ 可以直接 require() 不含顶层 await 的 ES Module,更早的版本需要改用动态 import()。

@tanstack/angular-query-experimental 可以商用吗?

@tanstack/angular-query-experimental 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@tanstack/angular-query-experimental 还在维护吗?

最新版本 5.105.2 发布于 2026/11/02(今天);至今共发布 333 个版本,其中过去 12 个月发布了 74 个;首次发布于 2023/12/01。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。