Bird
0
0

You wrote this code but Angular does not update the UI after the async task:

medium📝 Debug Q6 of 15
Angular - Change Detection
You wrote this code but Angular does not update the UI after the async task:
this.zone.runOutsideAngular(() => {
fetch('/data').then(() => {
this.data = 'loaded';
});
});

What is the problem?
Afetch API is not supported inside runOutsideAngular
BChange detection is not triggered because code runs outside Angular zone
CYou must call run() inside the then() callback to update UI
DThe data variable cannot be updated inside runOutsideAngular
Step-by-Step Solution
Solution:
  1. Step 1: Understand runOutsideAngular effect

    Code inside runOutsideAngular does not trigger Angular change detection automatically.
  2. Step 2: Analyze fetch then callback

    Updating this.data inside then() outside Angular zone won't update UI unless change detection runs.
  3. Final Answer:

    Change detection is not triggered because code runs outside Angular zone -> Option B
  4. Quick Check:

    runOutsideAngular skips change detection, so UI won't update automatically [OK]
Quick Trick: runOutsideAngular skips change detection; UI won't update automatically [OK]
Common Mistakes:
MISTAKES
  • Thinking fetch is blocked outside Angular zone
  • Assuming data can't be updated outside zone
  • Forgetting to re-enter Angular zone to update UI

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Angular Quizzes