Bird
0
0

Which of the following is the correct way to apply a trackBy function named identify in an Angular template using ngFor?

easy📝 Syntax Q3 of 15
Angular - Performance Optimization
Which of the following is the correct way to apply a trackBy function named identify in an Angular template using ngFor?
A<code>*ngFor="let item of items; trackByFn: identify"</code>
B<code>*ngFor="let item of items; trackByFn: identify()"</code>
C<code>*ngFor="let item of items; trackBy: identify()"</code>
D<code>*ngFor="let item of items; trackBy: identify"</code>
Step-by-Step Solution
Solution:
  1. Step 1: Syntax of trackBy

    The correct syntax uses trackBy: functionName without parentheses.
  2. Step 2: Analyze options

    *ngFor="let item of items; trackBy: identify" correctly uses trackBy: identify. Options B and D incorrectly use trackByFn, which is not valid. *ngFor="let item of items; trackBy: identify()" incorrectly calls the function with parentheses.
  3. Final Answer:

    *ngFor="let item of items; trackBy: identify" -> Option D
  4. Quick Check:

    trackBy expects a function reference, not a call [OK]
Quick Trick: Use trackBy: functionName without parentheses [OK]
Common Mistakes:
  • Using parentheses after the function name
  • Using incorrect directive name like trackByFn

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Angular Quizzes