Bird
0
0

Which approach fits best?

hard🚀 Application Q15 of 15
Angular - Change Detection
In a large Angular app, you want to optimize performance by reducing unnecessary view updates. You decide to keep the default change detection strategy but want to limit checks on a specific component. Which approach fits best?
AUse <code>ChangeDetectorRef.detach()</code> to stop change detection on that component manually
BSet <code>changeDetection: ChangeDetectionStrategy.Default</code> on that component
CUse <code>markForCheck()</code> to force detection every time
DReplace default strategy with OnPush on all components
Step-by-Step Solution
Solution:
  1. Step 1: Understand default strategy limits

    Default strategy runs change detection frequently, which can be costly in large apps.
  2. Step 2: Identify how to limit detection on one component

    Using ChangeDetectorRef.detach() stops change detection on that component until manually reattached.
  3. Step 3: Evaluate other options

    Setting default again does nothing new; markForCheck forces detection; OnPush changes strategy globally, not selectively.
  4. Final Answer:

    Use ChangeDetectorRef.detach() to stop change detection on that component manually -> Option A
  5. Quick Check:

    Detach stops detection selectively [OK]
Quick Trick: Detach change detector to pause updates on specific component [OK]
Common Mistakes:
MISTAKES
  • Thinking setting default again limits detection
  • Confusing markForCheck with stopping detection
  • Assuming OnPush is selective per component

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Angular Quizzes