Bird
0
0

Identify the error in this Angular template snippet:

medium📝 Debug Q6 of 15
Angular - Directives
Identify the error in this Angular template snippet:
<div [ngSwitch]="mode">
  <div *ngSwitchCase=active>Active Mode</div>
  <div *ngSwitchCase="inactive">Inactive Mode</div>
</div>
ANo error, code is correct
BMissing quotes around 'active' in *ngSwitchCase
CUsing *ngSwitchCase without *ngSwitchDefault
DIncorrect use of [ngSwitch] instead of *ngSwitch
Step-by-Step Solution
Solution:
  1. Step 1: Check syntax for string literals in *ngSwitchCase

    String values must be quoted. The first case lacks quotes around active.

  2. Step 2: Verify other parts

    [ngSwitch] is correct usage, default case is optional, so no error there.

  3. Final Answer:

    Missing quotes around 'active' in *ngSwitchCase -> Option B
  4. Quick Check:

    String cases need quotes [OK]
Quick Trick: Always quote string values in *ngSwitchCase [OK]
Common Mistakes:
  • Omitting quotes around string cases
  • Confusing [ngSwitch] with *ngSwitch
  • Thinking *ngSwitchDefault is mandatory

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Angular Quizzes