NG.II · Angular 22 practice question

A developer is implementing a data fetching mechanism using Angular's resource loading pattern. If the input signal driving the resource's parameters changes while the underlying network request is in flight, what is the expected behavior regarding the ongoing fetch operation?

const userId: Signal<string> = getUserId();

const userResource = resource({
  params: () => ({id: userId()}),
  loader: ({params, abortSignal}): Promise<User> => {
    return fetch(`users/${params.id}`, {signal: abortSignal}).then((res) => res.json());
  },
});
Choose one answer
Check answer and explanation

Correct answer: The resource automatically cancels the existing HTTP call, initiating a fresh request with the new parameters.

Explanation

When the parameters used by a resource change while it is in the process of loading, the intended behavior is for the resource to terminate the current, outstanding loading operation and start a new request using the updated parameters. This functionality is enabled by supplying an `abortSignal` to the underlying fetch mechanism.

Common trap

A scenario where the existing request completes even after parameter modifications, causing the new parameters to be disregarded, represents an inefficient situation prone to race conditions. Furthermore, suggesting that the resource immediately throws a synchronous error upon detecting a parameter shift is inconsistent with the established design pattern for resource loading cancellation.

Source: Angular docs: Async reactivity with resources — Aborting requests
Checked against the cited text on 2026-11-25.

Report an error in this question