NG.II · Angular 22 practice question
A developer is building a data flow where a subsequent data fetch relies on an ID obtained from a preceding data service. If they use `resource.value()` directly within the `params` function of the downstream resource, what is the primary consequence according to best practices?
const upstreamResource = resource({ /* ... */ });
const downstreamResource = resource({
params: () => {
const id = upstreamResource.value(); // Direct read
return id ? { itemId: id } : undefined;
},
loader: ({params}) => fetchDetail(params.itemId),
});
Check answer and explanation
Correct answer: The downstream resource will incorrectly remain in an 'idle' state even if the upstream resource has successfully loaded data.
Explanation
The correct outcome is that returning `undefined` from `params` causes the resource to enter an 'idle' state instead of accurately reflecting the upstream resource's status.
Common trap
The scenario where the downstream resource immediately throws an error because reading `.value()` outside of a computed context is disallowed is incorrect because the API permits direct reading, but the resulting behavior is flawed; the situation where the downstream resource pauses indefinitely until the upstream resource emits a specific 'ready' signal describes a state management issue not addressed by this particular pattern.
Source: Angular docs: Async reactivity with resources — Chaining vs. reading resource values directly
Checked against the cited text on 2026-11-25.