import { Component } from '@angular/core' import { createStore, injectSelector } from '@tanstack/angular-store' // Optionally, you can create stores outside of Angular components at module scope const petStore = createStore({ cats: 0, dogs: 0, }) @Component({ selector: 'app-root', standalone: true, template: `

Angular Store Hooks

This example creates a module-level store. Components read state with \`injectSelector\` and update it directly with \`store.setState\`.

Cats: {{ cats() }}

Dogs: {{ dogs() }}

Total votes: {{ total() }}

`, }) export class AppComponent { cats = injectSelector(petStore, (state) => state.cats) dogs = injectSelector(petStore, (state) => state.dogs) total = injectSelector(petStore, (state) => state.cats + state.dogs) addCat() { petStore.setState((prev) => ({ ...prev, cats: prev.cats + 1, })) } addDog() { // directly update values in the store petStore.setState((prev) => ({ ...prev, dogs: prev.dogs + 1, })) } }