Skip to the page

Angular core · Scenario

ExpressionChangedAfterItHasBeenCheckedError after adding a loader

The interviewer asks

A teammate added a loading flag to the shared layout. Now the console shows 'ExpressionChangedAfterItHasBeenCheckedError' on every page in development. Production looks fine. What's going on, and what do you do?

Then

Follow-ups the interviewer asks next

  1. Why does it show only in development?
  2. Read the error with me. What do 'previous value' and 'current value' tell you?
  3. Where is the value being changed, and why is that too late?
  4. A teammate wraps the change in setTimeout and the error goes away. Is that a fix?
  5. What is the proper fix here?
  6. How would signals change this?

The answer

What a strong answer covers

  • In development, Angular runs an extra check after each change-detection pass. If a binding's value changed between the two, it throws NG0100. It means data flowed "backwards": something changed a parent's binding after the parent was already checked.
  • It is not harmless: in production the screen can show a stale value until the next check.
  • Cause here: a page component sets loading = true on a shared service in ngAfterViewInit, after the layout above it was already rendered.
  • Fixes, in order: make the change earlier (ngOnInit or when the request starts), or derive the value instead of setting it, or hold the shared state in a signal so a change schedules a new check instead of changing a value in the middle of one.
  • setTimeout or Promise.resolve().then() only hides it by moving the change to a later round, and it can flicker. detectChanges() in the child is also a patch.

The red pen

Common traps

Avoid:"it's only in dev, ignore it"; setTimeout as the fix; turning off dev mode.

Practise this out loud

Say your answer out loud to an AI interviewer that follows up, and get a score for it.

Practise by voice

Practise questions like this out loud

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

Start your free interview