Build Angular's linkedSignal and resource(): params, loader aborts, status values, reload and local set
Problem
Angular 19 introduced two signal APIs that interviewers now ask about. linkedSignal is a writable signal that resets when another signal changes (a selected item that falls back to the first option when the list changes). resource() connects async work to signals: it runs a loader whenever its params change, cancels stale requests, and exposes the result as signals. Build both on top of the small signals core in the starter (keep the core as it is).
const userId = signal(7);
const user = resource({
params: () => ({ id: userId() }),
loader: ({ params, abortSignal }) => fetch(`/api/users/${params.id}`, { signal: abortSignal }).then((r) => r.json()),
});
user.status(); // "loading" (the loader has not run yet)
flushEffects(); // the loader runs
// ...later: user.status() === "resolved", user.value() is the user
userId.set(8); // "loading" again; the next flush aborts the request for 7Ref. UR-1451 · © UIRound · uiround.com/questions/build-angulars-linkedsignal-and-resource-params-loader-aborts-status-values-reload-and-local-set
Unlock this question
The full problem, its tests and the tested solution are part of Pro.
- 4
- code listings
- 7
- edge cases
- 5
- follow-up questions
What's inside
- The full problem, with examples
- Tests that check your solution
- Step-by-step
- Approach
- Solution
- Complexity
- Edge cases
- Follow-up questions
- Card worldwide
- UPI and net banking in India
- One-time payment, nothing renews
Stuck? Take a hint
- 1
resource()is mostly signals: a computed for the params, alinkedSignalholding{ status, value, error }that resets to loading whenever the params change, and one effect that calls the loader. BuildlinkedSignalfirst.
Try it in the editor
Run your code as often as you like. Submitting it to the full test suite is part of Pro.
Private, and saved in this browser as you type. All your notes are on My lists.