📄 tanstack/query/latest/docs/framework/angular/reference/functions/injectquery

File: injectquery.md | Updated: 11/15/2025

Source: https://tanstack.com/query/latest/docs/framework/angular/reference/functions/injectquery



TanStack

Query v5v5

Search...

+ K

Auto

Log In

TanStack StartRC

Docs Examples GitHub Contributors

TanStack Router

Docs Examples GitHub Contributors

TanStack Query

Docs Examples GitHub Contributors

TanStack Table

Docs Examples Github Contributors

TanStack Formnew

Docs Examples Github Contributors

TanStack DBbeta

Docs Github Contributors

TanStack Virtual

Docs Examples Github Contributors

TanStack Paceralpha

Docs Examples Github Contributors

TanStack Storealpha

Docs Examples Github Contributors

TanStack Devtoolsalpha

Docs Github Contributors

More Libraries

Maintainers Partners Support Learn StatsBETA Discord Merch Blog GitHub Ethos Brand Guide

Documentation

Framework

Angular logo

Angular

Version

Latest

Search...

+ K

Menu

Getting Started

Guides & Concepts

API Reference

ESLint

Examples

Framework

Angular logo

Angular

Version

Latest

Menu

Getting Started

Guides & Concepts

API Reference

ESLint

Examples

On this page

injectQuery

Copy Markdown

Function: injectQuery()
=======================

Injects a query: a declarative dependency on an asynchronous source of data that is tied to a unique key.

Basic example

ts

class ServiceOrComponent {
  query = injectQuery(() => ({
    queryKey: ['repoData'],
    queryFn: () =>
      this.#http.get<Response>('https://api.github.com/repos/tanstack/query'),
  }))
}


class ServiceOrComponent {
  query = injectQuery(() => ({
    queryKey: ['repoData'],
    queryFn: () =>
      this.#http.get<Response>('https://api.github.com/repos/tanstack/query'),
  }))
}

Similar to computed from Angular, the function passed to injectQuery will be run in the reactive context. In the example below, the query will be automatically enabled and executed when the filter signal changes to a truthy value. When the filter signal changes back to a falsy value, the query will be disabled.

Reactive example

ts

class ServiceOrComponent {
  filter = signal('')

  todosQuery = injectQuery(() => ({
    queryKey: ['todos', this.filter()],
    queryFn: () => fetchTodos(this.filter()),
    // Signals can be combined with expressions
    enabled: !!this.filter(),
  }))
}


class ServiceOrComponent {
  filter = signal('')

  todosQuery = injectQuery(() => ({
    queryKey: ['todos', this.filter()],
    queryFn: () => fetchTodos(this.filter()),
    // Signals can be combined with expressions
    enabled: !!this.filter(),
  }))
}

Param
-----

A function that returns query options.

Param
-----

Additional configuration

See
---

https://tanstack.com/query/latest/docs/framework/angular/guides/queries

Call Signature
--------------

ts

function injectQuery<TQueryFnData, TError, TData, TQueryKey>(injectQueryFn, options?): DefinedCreateQueryResult<TData, TError>


function injectQuery<TQueryFnData, TError, TData, TQueryKey>(injectQueryFn, options?): DefinedCreateQueryResult<TData, TError>

Defined in: inject-query.ts:65

Injects a query: a declarative dependency on an asynchronous source of data that is tied to a unique key.

Basic example

ts

class ServiceOrComponent {
  query = injectQuery(() => ({
    queryKey: ['repoData'],
    queryFn: () =>
      this.#http.get<Response>('https://api.github.com/repos/tanstack/query'),
  }))
}


class ServiceOrComponent {
  query = injectQuery(() => ({
    queryKey: ['repoData'],
    queryFn: () =>
      this.#http.get<Response>('https://api.github.com/repos/tanstack/query'),
  }))
}

Similar to computed from Angular, the function passed to injectQuery will be run in the reactive context. In the example below, the query will be automatically enabled and executed when the filter signal changes to a truthy value. When the filter signal changes back to a falsy value, the query will be disabled.

Reactive example

ts

class ServiceOrComponent {
  filter = signal('')

  todosQuery = injectQuery(() => ({
    queryKey: ['todos', this.filter()],
    queryFn: () => fetchTodos(this.filter()),
    // Signals can be combined with expressions
    enabled: !!this.filter(),
  }))
}


class ServiceOrComponent {
  filter = signal('')

  todosQuery = injectQuery(() => ({
    queryKey: ['todos', this.filter()],
    queryFn: () => fetchTodos(this.filter()),
    // Signals can be combined with expressions
    enabled: !!this.filter(),
  }))
}

### Type Parameters

TQueryFnData = unknown

TError = Error

TData = TQueryFnData

TQueryKey extends readonly unknown[] = readonly unknown[]

### Parameters #### injectQueryFn

() => DefinedInitialDataOptions <TQueryFnData, TError, TData, TQueryKey>

A function that returns query options.

#### options?

InjectQueryOptions

Additional configuration

### Returns

DefinedCreateQueryResult <TData, TError>

The query result.

The query result.

### Param

A function that returns query options.

### Param

Additional configuration

### See

https://tanstack.com/query/latest/docs/framework/angular/guides/queries

### See

https://tanstack.com/query/latest/docs/framework/angular/guides/queries

Call Signature
--------------

ts

function injectQuery<TQueryFnData, TError, TData, TQueryKey>(injectQueryFn, options?): CreateQueryResult<TData, TError>


function injectQuery<TQueryFnData, TError, TData, TQueryKey>(injectQueryFn, options?): CreateQueryResult<TData, TError>

Defined in: inject-query.ts:116

Injects a query: a declarative dependency on an asynchronous source of data that is tied to a unique key.

Basic example

ts

class ServiceOrComponent {
  query = injectQuery(() => ({
    queryKey: ['repoData'],
    queryFn: () =>
      this.#http.get<Response>('https://api.github.com/repos/tanstack/query'),
  }))
}


class ServiceOrComponent {
  query = injectQuery(() => ({
    queryKey: ['repoData'],
    queryFn: () =>
      this.#http.get<Response>('https://api.github.com/repos/tanstack/query'),
  }))
}

Similar to computed from Angular, the function passed to injectQuery will be run in the reactive context. In the example below, the query will be automatically enabled and executed when the filter signal changes to a truthy value. When the filter signal changes back to a falsy value, the query will be disabled.

Reactive example

ts

class ServiceOrComponent {
  filter = signal('')

  todosQuery = injectQuery(() => ({
    queryKey: ['todos', this.filter()],
    queryFn: () => fetchTodos(this.filter()),
    // Signals can be combined with expressions
    enabled: !!this.filter(),
  }))
}


class ServiceOrComponent {
  filter = signal('')

  todosQuery = injectQuery(() => ({
    queryKey: ['todos', this.filter()],
    queryFn: () => fetchTodos(this.filter()),
    // Signals can be combined with expressions
    enabled: !!this.filter(),
  }))
}

### Type Parameters

TQueryFnData = unknown

TError = Error

TData = TQueryFnData

TQueryKey extends readonly unknown[] = readonly unknown[]

### Parameters #### injectQueryFn

() => UndefinedInitialDataOptions <TQueryFnData, TError, TData, TQueryKey>

A function that returns query options.

#### options?

InjectQueryOptions

Additional configuration

### Returns

CreateQueryResult <TData, TError>

The query result.

The query result.

### Param

A function that returns query options.

### Param

Additional configuration

### See

https://tanstack.com/query/latest/docs/framework/angular/guides/queries

### See

https://tanstack.com/query/latest/docs/framework/angular/guides/queries

Call Signature
--------------

ts

function injectQuery<TQueryFnData, TError, TData, TQueryKey>(injectQueryFn, options?): CreateQueryResult<TData, TError>


function injectQuery<TQueryFnData, TError, TData, TQueryKey>(injectQueryFn, options?): CreateQueryResult<TData, TError>

Defined in: inject-query.ts:167

Injects a query: a declarative dependency on an asynchronous source of data that is tied to a unique key.

Basic example

ts

class ServiceOrComponent {
  query = injectQuery(() => ({
    queryKey: ['repoData'],
    queryFn: () =>
      this.#http.get<Response>('https://api.github.com/repos/tanstack/query'),
  }))
}


class ServiceOrComponent {
  query = injectQuery(() => ({
    queryKey: ['repoData'],
    queryFn: () =>
      this.#http.get<Response>('https://api.github.com/repos/tanstack/query'),
  }))
}

Similar to computed from Angular, the function passed to injectQuery will be run in the reactive context. In the example below, the query will be automatically enabled and executed when the filter signal changes to a truthy value. When the filter signal changes back to a falsy value, the query will be disabled.

Reactive example

ts

class ServiceOrComponent {
  filter = signal('')

  todosQuery = injectQuery(() => ({
    queryKey: ['todos', this.filter()],
    queryFn: () => fetchTodos(this.filter()),
    // Signals can be combined with expressions
    enabled: !!this.filter(),
  }))
}


class ServiceOrComponent {
  filter = signal('')

  todosQuery = injectQuery(() => ({
    queryKey: ['todos', this.filter()],
    queryFn: () => fetchTodos(this.filter()),
    // Signals can be combined with expressions
    enabled: !!this.filter(),
  }))
}

### Type Parameters

TQueryFnData = unknown

TError = Error

TData = TQueryFnData

TQueryKey extends readonly unknown[] = readonly unknown[]

### Parameters #### injectQueryFn

() => CreateQueryOptions <TQueryFnData, TError, TData, TQueryKey>

A function that returns query options.

#### options?

InjectQueryOptions

Additional configuration

### Returns

CreateQueryResult <TData, TError>

The query result.

The query result.

### Param

A function that returns query options.

### Param

Additional configuration

### See

https://tanstack.com/query/latest/docs/framework/angular/guides/queries

### See

https://tanstack.com/query/latest/docs/framework/angular/guides/queries

Edit on GitHub

Angular Reference

Functions / injectMutation

Partners Become a Partner

Code RabbitCode Rabbit CloudflareCloudflare AG GridAG Grid NetlifyNetlify NeonNeon WorkOSWorkOS ClerkClerk ConvexConvex ElectricElectric SentrySentry PrismaPrisma StrapiStrapi UnkeyUnkey

[###### Want to Skip the Docs?

Query.gg - The Official React Query Course
\

“If you’re serious about *really* understanding React Query, there’s no better way than with query.gg”—Tanner Linsley

Learn More](https://query.gg/?s=tanstack)

scarf analytics