Counter stuck at 0 after an OnPush refactor

intermediate
By FrontendAtlas Editorial · Updated Nov 12, 2026
The counter display moved into its own OnPush component to save change detection work. Since then, clicking Increment leaves the number on screen at 0, although the click handler runs on every click. Find why Angular skips the display and fix it so every click shows the new count. Keep CounterDisplayComponent on ChangeDetectionStrategy.OnPush.

Solution idea

inc() adds 1 to stats.count in place, so the object bound to [stats] is the same reference after every click. Angular checks an OnPush component only when an input receives a new value (compared by reference), when an event fires in its own template, or when a signal its template reads changes. The mutation meets none of these: the stats input signal keeps the same object, so Angular skips CounterDisplayComponent and the paragraph keeps its first render while the real count grows.