Bird
0
0

Which of the following is the correct syntax to use *ngFor to loop over a list named fruits?

easy📝 Syntax Q12 of 15
Angular - Directives
Which of the following is the correct syntax to use *ngFor to loop over a list named fruits?
A<code>*ngFor="let fruit in fruits"</code>
B<code>*ngFor="fruits as fruit"</code>
C<code>*ngFor="fruit of fruits"</code>
D<code>*ngFor="let fruit of fruits"</code>
Step-by-Step Solution
Solution:
  1. Step 1: Recall correct Angular syntax

    The correct syntax for *ngFor uses let variable of list to iterate over the list.
  2. Step 2: Compare options

    *ngFor="let fruit of fruits" uses let fruit of fruits, which matches the correct syntax. *ngFor="let fruit in fruits" uses 'in' which is incorrect in Angular templates.
  3. Final Answer:

    *ngFor="let fruit of fruits" -> Option D
  4. Quick Check:

    Use 'of' not 'in' in *ngFor syntax = B [OK]
Quick Trick: Use 'let item of list' syntax for *ngFor loops [OK]
Common Mistakes:
  • Using 'in' instead of 'of'
  • Omitting 'let' keyword
  • Swapping variable and list positions

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Angular Quizzes