Bird
0
0

Which of the following is the correct way to declare the loop variable in *ngFor?

easy📝 Conceptual Q2 of 15
Angular - Directives
Which of the following is the correct way to declare the loop variable in *ngFor?
A*ngFor="let item of items"
B*ngFor="item in items"
C*ngFor="var item of items"
D*ngFor="each item of items"
Step-by-Step Solution
Solution:
  1. Step 1: Recall Angular syntax for *ngFor

    The correct syntax uses let to declare the loop variable.

  2. Step 2: Identify incorrect keywords

    Keywords like in, var, or each are not valid in Angular *ngFor.

  3. Final Answer:

    *ngFor="let item of items" -> Option A
  4. Quick Check:

    Loop variable declared with let = *ngFor="let item of items" [OK]
Quick Trick: Always use 'let' to declare the loop variable in *ngFor [OK]
Common Mistakes:
  • Using 'in' instead of 'of'
  • Using 'var' instead of 'let'
  • Using 'each' keyword

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Angular Quizzes