NG.II · Angular 22 practice question
A developer is building a component that needs to display real-time updates from a live data feed, like a WebSocket connection. They are using Angular's resource functionality. Which approach should they employ to ensure the signal automatically reflects every incoming data packet?
const liveData = signal(null);
const feedResource = resource({
stream: () => liveData,
});
Check answer and explanation
Correct answer: Use `resource` with a `stream` provider, as this signal will continuously update as new data arrives.
Explanation
The appropriate approach is to 'Use `resource` with a `stream` provider, as this signal will continuously update as new data arrives.' This is because the official documentation indicates that the `stream` mechanism is intended for data sources that provide ongoing updates.
Common trap
The suggestion to 'Use `loader` because it is designed to handle continuous data streams over time' is flawed because the documentation explicitly states that `loader` resolves only once per request, making it inappropriate for persistent updates. Furthermore, the idea to 'Use a standard `signal` and manually subscribe to the data source outside of the resource context' circumvents the resource management pattern that is intended for this scenario.
Source: Angular docs: Async reactivity with resources — Streaming resources
Checked against the cited text on 2026-11-25.