Skip to main content
cngx-src documentation

injectAsyncState

Functioncommon/data/async-state

projects/common/data/async-state/inject-async-state.ts

Description#

Create a reactive async state that auto-loads when signal dependencies change.

Must be called in an injection context (field initializer or constructor). The computation function is tracked by Angular's effect() — any signal read inside fn will cause a re-load when it changes.

readonly residents = injectAsyncState(
  () => this.api.getResidents(this.filter())
);
// Loads automatically when filter() changes.
// Caches last result during refresh (refreshing state).
// Deduplicates parallel requests.

Signature#

injectAsyncState(fn, options?: InjectAsyncStateOptions)

Parameters#

@paramfn

Returns#

ReactiveAsyncState