Skip to the page

Dependency injection and change detection · mid

OnPush, Eager and ExpressionChangedAfterItHasBeenChecked

OnPush checks a component only when an input changes by reference, an event happens in it, or a signal it reads changes. In v22 OnPush is the default and the old behaviour is called Eager. NG0100 means data flowed backwards during a check.

The notes

What you must know

  • OnPush checks a child when an input changes by reference (===), not when the contents of the same array change.
  • push keeps the same array, so an OnPush child is skipped. Fix: an immutable update [...list, item], or a signal with update(list => [...list, item]).
  • markForCheck() on the child also works but hides the real design problem.
  • In v22, components without a changeDetection setting are OnPush. ng update marks existing ones Eager so old screens behave the same (facts.md).
  • Breaking patterns after v22: mutating an array that is passed as an input, and setting plain fields after async work without a signal.
  • NG0100: in development Angular checks a second time. If a binding changed between the two checks, it throws. Something changed a parent value after the parent was checked.
  • Typical cause: a child sets a shared loading flag in ngAfterViewInit. It is not harmless: in production the screen may show a stale value.

The red pen

Common traps: mistake → fix

  • Mistake: OnPush never updates

    Fix: it updates on input reference change, events and signals.

  • Mistake: NG0100 is only a dev warning I can ignore

    Fix: production can show stale data.

Easy to hard

Questions interviewers ask, easy to hard

  1. What is the difference between Default (Eager) and OnPush change detection?
  2. Why does OnPush not see array.push?
  3. What is NG0100 and how do you fix it?
  4. After upgrading to v22, new screens do not refresh. Why?

Practise

Practise with these questions

Explain it out loud

Explain it out loud to an AI interviewer that follows up, and see where your answer is thin.

Practise by voice

Your first interview is free

Sign up and start with a 15-minute interview with the full report, and an English conversation. No card needed.

Start your free interview