Sub topic 15
Diagnosing views that do not update
This chapter assumes you know standalone components, signals (signal, computed), OnPush, and markForCheck(). It gives you a repeatable way to find out why a zoneless app shows stale data.
Why views go stale
In a zoneless app, Angular schedules change detection only when something notifies it. Without a notification, the view stays as it was, even though the component's data has changed. Nearly every missed update comes from one of two causes:
- The state change happened in a plain field, so nothing told Angular.
- The state change happened somewhere Angular cannot see, such as a third-party callback or a timer.
The notifications that do schedule change detection are:
- A signal read in a template changes.
- A template or host listener event fires.
markForCheck()is called.- The
asyncpipe receives a new value. - A view is attached or removed.
If none of these happened, the view will not refresh.
A diagnostic flow
Work through the questions in order. Stop at the first one that fits.
Common causes and fixes
A plain field changes in a callback
This is the most frequent case. The field changes, and nothing notifies Angular.
import { ChangeDetectionStrategy, Component } from '@angular/core';
@Component({
selector: 'app-stale-timer',
changeDetection: ChangeDetectionStrategy.OnPush,
template: `<p>Seconds: {{ seconds }}</p>`,
})
export class StaleTimer {
protected seconds = 0;
constructor() {
setInterval(() => this.seconds++, 1000);
}
}The view shows 0 forever. Prefer a signal:
import { ChangeDetectionStrategy, Component, signal } from '@angular/core';
@Component({
selector: 'app-fixed-timer',
changeDetection: ChangeDetectionStrategy.OnPush,
template: `<p>Seconds: {{ seconds() }}</p>`,
})
export class FixedTimer {
protected readonly seconds = signal(0);
constructor() {
setInterval(() => this.seconds.update((s) => s + 1), 1000);
}
}If you cannot change the field, call markForCheck() after each change, as in the earlier chapter on non-signal state.
A signal holds an object that is mutated
A signal notifies only when its value changes by reference. Pushing to an array held in a signal does nothing visible.
import { signal } from '@angular/core';
const items = signal<string[]>([]);
// Wrong: same array reference, no notification
items().push('a');
// Right: new array, notification sent
items.update((list) => [...list, 'a']);The signal is not read in the template
Angular tracks signals that are read during rendering. If the template reads a copy, such as a value captured in the constructor, there is no dependency to track.
// Wrong: captured once
protected label = this.name();
// Right: stays reactive
protected readonly label = computed(() => this.name().toUpperCase());A callback runs outside Angular's view
Callbacks from libraries such as charting widgets or IntersectionObserver do not notify Angular. Write the result to a signal inside the callback.
Check the errors first
A thrown error inside a listener or effect can stop an update. Open the browser console before anything else.
Dev-mode help
In development, Angular can warn about a binding that changed after it was checked. You see ExpressionChangedAfterItHasBeenChecked when a value changes during rendering. Move that write into an effect, an event handler, or the signal's source.
Exercise
A component keeps results: string[] = [] as a plain field and runs this.results = await load() after a button click. The view does not update. Name two fixes.
Show answer
Make results a signal and call results.set(await load()), with the template reading results(). Or keep the field and call this.cdr.markForCheck() after the assignment. The signal is preferred because it notifies Angular without an extra call.
Exercise
A signal holds an array, and the code calls list().push(item). Why does the view not change, and how do you fix it?
Show answer
The array keeps the same reference, so the signal sees no change. Use list.update((l) => [...l, item]) to set a new array.