Bird
0
0

What will be the output of this template?

medium📝 component behavior Q5 of 15
Angular - Directives
What will be the output of this template?
<div *ngFor="let num of [1,2,3]; let idx = index">{{idx}}: {{num}}</div>
A0: 1 1: 2 2: 3
B1: 1 2: 2 3: 3
Cindex: num repeated 3 times
DSyntax error due to index alias
Step-by-Step Solution
Solution:
  1. Step 1: Identify index and value usage

    The idx variable holds the zero-based index, and num holds the current number.

  2. Step 2: Understand output format

    Each <div> shows index and number separated by colon.

  3. Final Answer:

    0: 1 1: 2 2: 3 -> Option A
  4. Quick Check:

    Index starts at 0, displayed with value = 0: 1 1: 2 2: 3 [OK]
Quick Trick: Index starts at 0 in *ngFor loops [OK]
Common Mistakes:
  • Assuming index starts at 1
  • Misusing index alias
  • Syntax errors with let declarations

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Angular Quizzes