Bird
0
0

What is the main purpose of using trackBy in an ngFor directive in Angular?

easy📝 Conceptual Q11 of 15
Angular - Performance Optimization
What is the main purpose of using trackBy in an ngFor directive in Angular?
ATo improve performance by uniquely identifying list items during updates
BTo style list items differently based on their index
CTo sort the list items before rendering
DTo filter out duplicate items from the list
Step-by-Step Solution
Solution:
  1. Step 1: Understand what ngFor does

    ngFor repeats a template for each item in a list, rendering them in the view.
  2. Step 2: Identify the role of trackBy

    trackBy helps Angular know which items changed by uniquely identifying them, so it only updates those items instead of re-rendering the whole list.
  3. Final Answer:

    To improve performance by uniquely identifying list items during updates -> Option A
  4. Quick Check:

    TrackBy improves performance = C [OK]
Quick Trick: TrackBy helps Angular track items uniquely for faster updates [OK]
Common Mistakes:
  • Thinking trackBy sorts or filters items
  • Believing trackBy changes item styles
  • Assuming trackBy removes duplicates

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Angular Quizzes