Bird
0
0

Given the following Angular template code, what will be rendered?

medium📝 component behavior Q13 of 15
Angular - Directives
Given the following Angular template code, what will be rendered?
<ul>
  <li *ngIf="showItem">Item 1</li>
  <li>Item 2</li>
</ul>

Assuming showItem is false.
ANo output, error occurs
B<ul><li>Item 1</li><li>Item 2</li></ul>
C<ul></ul>
D<ul><li>Item 2</li></ul>
Step-by-Step Solution
Solution:
  1. Step 1: Understand *ngIf behavior with false condition

    *ngIf removes the element from the DOM if the condition is false.
  2. Step 2: Apply this to the template

    The first <li> with *ngIf="showItem" will not render because showItem is false. The second <li> renders normally.
  3. Final Answer:

    <ul><li>Item 2</li></ul> -> Option D
  4. Quick Check:

    *ngIf false removes element [OK]
Quick Trick: *ngIf false means element is removed, not hidden [OK]
Common Mistakes:
  • Thinking *ngIf hides element but keeps it in DOM
  • Assuming both list items render regardless
  • Confusing *ngIf with attribute directives

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Angular Quizzes