Bird
0
0

Which of these is the correct syntax to use *ngIf with an else template?

easy📝 Syntax Q3 of 15
Angular - Directives
Which of these is the correct syntax to use *ngIf with an else template?
A
Content shown
else No content
B
Content shown
No content
C
Content shown
No content
D
Content shown
No content
Step-by-Step Solution
Solution:
  1. Step 1: Recall *ngIf else syntax

    The correct syntax uses *ngIf="condition; else templateRef" and a separate <ng-template> with the matching reference.
  2. Step 2: Match syntax with options

    Content shown
    No content correctly uses else noContent and defines <ng-template #noContent>. Others misuse else or template references.
  3. Final Answer:

    <div *ngIf="isVisible; else noContent">Content shown</div><ng-template #noContent>No content</ng-template> -> Option B
  4. Quick Check:

    *ngIf else syntax =
    Content shown
    No content [OK]
Quick Trick: Use *ngIf="cond; else templateRef" with <ng-template> [OK]
Common Mistakes:
  • Placing else outside the *ngIf attribute
  • Using else without ng-template
  • Incorrect template reference syntax

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Angular Quizzes