Bird
0
0

You have a component rendering a large list with *ngFor using Default change detection. Which approach improves performance without switching to OnPush?

hard📝 component behavior Q8 of 15
Angular - Change Detection
You have a component rendering a large list with *ngFor using Default change detection. Which approach improves performance without switching to OnPush?
AManually call detectChanges() after every update
BImplement a trackBy function to optimize list rendering
CWrap the list in a separate component with OnPush strategy
DUse two-way binding on all list items
Step-by-Step Solution
Solution:
  1. Step 1: Understand Default Strategy

    Default runs change detection frequently, which can be costly for large lists.
  2. Step 2: Optimize with trackBy

    Using trackBy helps Angular identify items uniquely, reducing DOM manipulations.
  3. Step 3: Evaluate Options

    Only trackBy improves performance without changing detection strategy.
  4. Final Answer:

    Implement a trackBy function to optimize list rendering -> Option B
  5. Quick Check:

    trackBy reduces DOM updates in large lists [OK]
Quick Trick: Use trackBy with *ngFor to boost performance [OK]
Common Mistakes:
MISTAKES
  • Thinking detectChanges() improves performance
  • Assuming wrapping in OnPush component is allowed
  • Using two-way binding unnecessarily

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Angular Quizzes