@void-snippets/angular

MaybeSignal

Reactive params — pass a Signal and queries refetch automatically when it changes.

#What it does

type MaybeSignal = T | Signal. Every param argument in injectList, injectGet, and injectInfinite accepts either a plain value or an Angular Signal wrapping that value. This is the Angular-native reactivity model: query params become automatically reactive with zero extra code.

#The problem it solves

React re-runs a hook on every render, so re-fetching on param change is implicit. Angular is push-based — a component does not "re-render" to run a function again. By accepting Signal, injectList/injectGet/injectInfinite read the signal inside the TanStack query callback, so TanStack tracks it as a reactive dependency and re-runs the query the moment the signal's value changes.

#Signature

typescript
type MaybeSignal<T> = T | Signal<T>;

function resolveSignal<T>(input: MaybeSignal<T>): Signal<T>;

#Example

typescript
// Static — params never change, one-time fetch
const contacts = contactResource.injectList({ page: 1 });

// Reactive — auto-refetches when the signal's value changes
const page = signal(1);
const contacts = contactResource.injectList(computed(() => ({ page: page() })));

// Computed from several pieces of component state
const filters = computed(() => ({
  page: this.currentPage(),
  q:    this.searchQuery(),
  sort: this.sortOrder(),
}));
const contacts = contactResource.injectList(filters);
// Whenever currentPage, searchQuery, or sortOrder changes → automatic refetch