Bird
0
0

You want to display a list of users with their position starting from 1. Which template code correctly achieves this?

hard📝 Application Q8 of 15
Angular - Directives
You want to display a list of users with their position starting from 1. Which template code correctly achieves this?
<div *ngFor="let user of users; let i = index">{{i + 1}} - {{user.name}}</div>
AYou must use 'let i = position' to start at 1
BIndex starts at 0, so this will show positions starting at 0
CThis code correctly shows positions starting at 1
DThis code will cause a runtime error
Step-by-Step Solution
Solution:
  1. Step 1: Understand index behavior

    The index variable starts at 0 in *ngFor.

  2. Step 2: Adjust index for display

    Adding 1 to i shifts the display to start at 1.

  3. Final Answer:

    This code correctly shows positions starting at 1 -> Option C
  4. Quick Check:

    Index + 1 shows position starting at 1 [OK]
Quick Trick: Add 1 to index to display positions starting at 1 [OK]
Common Mistakes:
  • Expecting index to start at 1
  • Using wrong variable name
  • Forgetting to add 1

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Angular Quizzes