Angular - Directives
Why does Angular require the use of
*ngSwitchDefault instead of an empty *ngSwitchCase for the default case?Step-by-Step Solution
Solution:
Step 1: Understand the role of *ngSwitchCase values
*ngSwitchCasemust have a value to compare with the switch expression.Step 2: Explain why empty *ngSwitchCase is invalid
An empty
*ngSwitchCasehas no value to match, causing Angular to throw an error.Final Answer:
*ngSwitchCase requires a value to match, empty cases cause errors. -> Option DQuick Check:
Default case uses *ngSwitchDefault, not empty *ngSwitchCase [OK]
Quick Trick: Default case must use *ngSwitchDefault, not empty *ngSwitchCase [OK]
Common Mistakes:
- Trying to use empty *ngSwitchCase as default
- Believing *ngSwitchDefault is optional
- Thinking *ngSwitchCase can have multiple empty cases
Master "Directives" in Angular
Want More Practice?
15+ quiz questions · All difficulty levels · Free
Free Signup - Practice All QuestionsMore Angular Quizzes
