Bird
0
0

Identify the error in this template:

medium📝 Debug Q6 of 15
Angular - Directives
Identify the error in this template:
<div *ngIf="isVisible; else noContent">Visible</div>
<ng-template noContent>Hidden</ng-template>
AThe <code>*ngIf</code> syntax is incorrect; else cannot be used.
BThere is no error; the code is correct.
CThe <code>div</code> tag cannot have <code>*ngIf</code> directive.
DThe <code>ng-template</code> is missing the template reference variable (#).
Step-by-Step Solution
Solution:
  1. Step 1: Check else template reference

    The else clause requires a template reference variable with # on the ng-template.
  2. Step 2: Identify missing #

    Here, <ng-template noContent> lacks #noContent, so Angular cannot find the template.
  3. Final Answer:

    The ng-template is missing the template reference variable (#). -> Option D
  4. Quick Check:

    Always add # to ng-template for else [OK]
Quick Trick: Add # before template name in ng-template for else [OK]
Common Mistakes:
  • Omitting # in ng-template reference
  • Misusing else syntax
  • Thinking *ngIf can't be on div

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Angular Quizzes