Bird
0
0

You want to display different messages for user roles: 'admin', 'editor', 'guest', and a default for others. Which Angular template correctly uses *ngSwitch to handle this?

hard📝 Application Q15 of 15
Angular - Directives
You want to display different messages for user roles: 'admin', 'editor', 'guest', and a default for others. Which Angular template correctly uses *ngSwitch to handle this?
A
Admin Panel
Editor Dashboard
Welcome Guest
Access Denied
B
Admin Panel
Editor Dashboard
Welcome Guest
Access Denied
C
Admin Panel
Editor Dashboard
Welcome Guest
Access Denied
D
Admin Panel
Editor Dashboard
Welcome Guest
Access Denied
Step-by-Step Solution
Solution:
  1. Step 1: Check the main [ngSwitch] binding

    The main switch must use property binding syntax: [ngSwitch]="userRole".
  2. Step 2: Verify *ngSwitchCase values are strings with quotes

    Each case value is a string and must be quoted like *ngSwitchCase="'admin'".
  3. Step 3: Confirm default case is present

    The default case uses *ngSwitchDefault without a value, which is correct.
  4. Final Answer:

    Correctly uses [ngSwitch] and quotes string cases -> Option D
  5. Quick Check:

    Use [ngSwitch] and quote string cases = D [OK]
Quick Trick: Use [ngSwitch] and quote string cases in *ngSwitchCase [OK]
Common Mistakes:
  • Using *ngSwitch instead of [ngSwitch]
  • Not quoting string case values
  • Missing *ngSwitchDefault block

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Angular Quizzes