Bird
0
0

Which of the following is the correct syntax for using the structural directive that repeats elements in Angular?

easy📝 Syntax Q12 of 15
Angular - Directives
Which of the following is the correct syntax for using the structural directive that repeats elements in Angular?
A<code><div *ngFor="let item of items">{{item}}</div></code>
B<code><div [ngFor]="items">{{item}}</div></code>
C<code><div (ngFor)="items">{{item}}</div></code>
D<code><div #ngFor="items">{{item}}</div></code>
Step-by-Step Solution
Solution:
  1. Step 1: Recall the syntax for the structural directive *ngFor

    The correct syntax uses an asterisk (*) before ngFor and a let variable to iterate.
  2. Step 2: Check each option's syntax

    Only <div *ngFor="let item of items">{{item}}</div> uses *ngFor="let item of items" which is correct.
  3. Final Answer:

    <div *ngFor="let item of items">{{item}}</div> -> Option A
  4. Quick Check:

    *ngFor syntax = <div *ngFor="let item of items">{{item}}</div> [OK]
Quick Trick: Structural directives use * before directive name [OK]
Common Mistakes:
  • Using square brackets [] instead of * for structural directives
  • Using parentheses () which are for events
  • Using template reference (#) incorrectly

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Angular Quizzes