Bird
0
0

Why does this Angular template cause an error?

medium📝 Debug Q7 of 15
Angular - Directives
Why does this Angular template cause an error?
<li *ngFor="let item of items" *ngIf="item.visible">{{item.name}}</li>
AngIf must be placed before ngFor
BCannot use two structural directives on the same element
CngFor requires a trackBy function when combined with ngIf
DngIf cannot be used inside list elements
Step-by-Step Solution
Solution:
  1. Step 1: Understand Angular structural directive rules

    Angular does not allow more than one structural directive on the same element.
  2. Step 2: Analyze the template

    Both *ngFor and *ngIf are structural directives on the same <li> element, causing an error.
  3. Final Answer:

    Cannot use two structural directives on the same element -> Option B
  4. Quick Check:

    Only one structural directive per element [OK]
Quick Trick: One element = one structural directive only [OK]
Common Mistakes:
  • Trying to combine multiple * directives on one element
  • Assuming order of directives fixes the error

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Angular Quizzes