tinycodinglm / lang /angular-changedetection.jsonl
winapiadmin's picture
Upload folder using huggingface_hub (part 15)
b27bfb3 verified
|
Raw History Blame Contribute Delete
1.24 kB
opencode trace
System You are an expert software engineer.

You are an expert software engineer.

User

How does Angular's change detection work?

Assistant

Angular has two scheduling modes:

Zone-based (traditional):

  1. Zone.js intercepts async operations
  2. NgZone.onMicrotaskEmpty emits when microtask queue empties
  3. NgZoneChangeDetectionScheduler triggers ApplicationRef._tick()

Zoneless (modern):

  1. ChangeDetectionScheduler.notify(source) explicit notifications
  2. Multiple notifications coalesced into single tick
  3. Uses scheduleCallbackWithRafRace

Component strategies:

  • Default: always checked during CD (LViewFlags.CheckAlways)
  • OnPush: only checked when dirty, inputs change, or signals update

Dirty checking: detectChangesInternal -> detectChangesInViewWhileDirty -> detectChangesInView. Infinite loop protection (>100 reruns throws error).

Signal integration: signal updates set ViewTreeTraversal flag. Computed signals lazily re-evaluate when dependencies change.