Bird
0
0

In this Angular snippet:

medium📝 Debug Q7 of 15
Angular - Change Detection
In this Angular snippet:
ngOnInit() {
  this.value = 10;
  this.cd.detectChanges();
  this.value = 20;
}

Why might the view show 10 instead of 20 after initialization?
AdetectChanges() was called before the last value update
BdetectChanges() freezes the view at 10
CAngular does not support detectChanges() in ngOnInit
DThe value 20 is ignored by Angular
Step-by-Step Solution
Solution:
  1. Step 1: Analyze order of value updates and detectChanges()

    detectChanges() runs after value is 10 but before it changes to 20.
  2. Step 2: Understand view update timing

    The view updates to 10, then value changes to 20 without triggering detection again.
  3. Final Answer:

    detectChanges() was called before the last value update -> Option A
  4. Quick Check:

    Detection timing matters for view updates [OK]
Quick Trick: Call detectChanges() after all data updates [OK]
Common Mistakes:
MISTAKES
  • Thinking detectChanges() freezes view
  • Believing detectChanges() unsupported in ngOnInit
  • Assuming Angular ignores last value

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Angular Quizzes