NG.II · Angular 22 practice question
A developer is using the `resource` API to fetch user data. They want to access the current loading state, whether the data has arrived, or any errors encountered during the fetch operation, without subscribing to the resource itself. Which property should they use?
const userResource = resource({
params: () => ({id: userId()}),
loader: ({params}) => fetchUser(params),
});
const snapshot = userResource.snapshot;
Check answer and explanation
Correct answer: The `snapshot` property, which yields a signal encapsulating the resource's current status, value, or error.
Explanation
The appropriate mechanism is 'The `snapshot` property, which yields a signal encapsulating the resource's current status, value, or error.' This is because the official documentation mandates that every resource possesses a `snapshot` property that delivers a signal reflecting its present condition, which encompasses status, value, or error.
Common trap
The '`state` property, which directly exposes a reactive object containing the loading status and result' is misleading because, despite suggesting state management, it is not the designated API for this function. Furthermore, the '`currentValue()` method, which must be called on the resource instance to retrieve the latest data' is incorrect because the source material indicates that the snapshot is a signal, not a method call.
Source: Angular docs: Async reactivity with resources — Resource composition with snapshots
Checked against the cited text on 2026-11-25.