Skip to main content
TanStack Store provides Angular support through the @tanstack/angular-store package, which integrates with Angular’s modern signals-based reactivity system.

Installation

Install the Angular adapter package:
The @tanstack/angular-store package re-exports everything from @tanstack/store, so you only need to install the Angular package.

Angular Version Requirements

This package requires Angular 19+ as it uses the modern signals API including linkedSignal and Signal.

Basic Usage

The primary way to use TanStack Store in Angular is through the injectStore function:

The injectStore Function

The injectStore function subscribes your component to store updates and returns an Angular Signal that automatically updates.

Signature

Parameters

  • store - The store instance to subscribe to
  • selector - (Optional) A function that selects which part of the state you need. Defaults to returning the entire state
  • options.equal - (Optional) A custom equality function. Defaults to shallow
  • options.injector - (Optional) A custom injector. If not provided, must be called within an injection context

Return Value

Returns a readonly Angular Signal<TSelected>. Call it like count() to get the current value.

Injection Context

injectStore must be called within an injection context (constructor, field initializer, or factory function) unless you provide a custom injector.

Selector Optimization

The selector function allows you to subscribe to only the parts of state you need:

Custom Equality Functions

For complex state selections, provide a custom equality function:

Shallow Equality

The package uses shallow equality by default for object comparisons:

Complete Example: Todo App

Here’s a complete Todo application using Angular standalone components:

Angular-Specific Considerations

Signals Integration

The Angular adapter uses linkedSignal internally:
  • Fully integrates with Angular’s signals API
  • Works with computed() and effect()
  • Automatically handles cleanup with DestroyRef

Working with Angular Signals

Dependency Injection

Create injectable services for your stores:

Server-Side Rendering (SSR)

TanStack Store works with Angular Universal:

Performance Tips

  1. Use selective subscriptions: Subscribe only to the state you need
  2. Leverage signals: Combine with computed() for derived state
  3. Injectable services: Wrap stores in services for better organization
  4. OnPush change detection: Works perfectly with signals-based stores

Derived Stores

Create derived stores that react to other stores:

API Reference

For detailed API documentation, see:
  • See the API reference for detailed documentation:

TypeScript Support

The Angular adapter provides full TypeScript support: