Skip to main content

Reference

injectStore

An Angular injection function that subscribes to a TanStack Store atom and returns a readonly signal. The signal will update when the selected state changes according to the equality function.
Atom<TState> | ReadonlyAtom<TState>
The store atom to subscribe to.
(state: TState) => TSelected
default:"(d) => d"
Optional function that selects a slice of state from the atom. Defaults to returning the entire state.
CreateSignalOptions<TSelected> & { injector?: Injector }
Optional configuration object.

Returns

Signal<TSelected>
An Angular readonly signal containing the selected state value.

Usage

Basic Usage

Selecting Multiple Values

Custom Equality Function

Using Entire State

With Computed Signals

With Custom Injector

Control Flow with @if

With @for Loop

Notes

  • Must be called within an injection context (constructor, field initializer) or provide a custom injector
  • Returns an Angular readonly signal - access the value by calling it as a function
  • Uses linkedSignal internally for optimal Angular reactivity
  • Automatically cleans up subscriptions using DestroyRef
  • Defaults to shallow equality comparison
  • Compatible with Angular’s signals and computed values
  • Works seamlessly with Angular’s control flow syntax (@if, @for, etc.)