NG.II · Angular 22 practice question
A developer is creating an `effect` that must execute only when a user profile signal changes, even if another unrelated counter signal is read inside the effect's body. To ensure the counter's updates do not trigger the effect, what approach should be used when accessing the counter signal?
effect(() => {
const user = currentUser();
console.log(`User: ${user} and Counter: ${untracked(counter())}`);
});
Check answer and explanation
Correct answer: Wrap the counter signal access within `untracked()` to prevent dependency tracking.
Explanation
The recommended method is to 'Wrap the counter signal access within `untracked()` to prevent dependency tracking,' because this explicitly instructs Angular not to register the read as a dependency for triggering the effect.
Common trap
The suggestion to 'Use `computed(() => counter())` inside the effect to isolate the reading' is flawed because `computed` is designed for deriving values, not for selectively disabling dependency tracking within an active effect.
Source: Angular docs: guide/signals/overview — Reading without tracking dependencies
Checked against the cited text on 2026-11-25.