Bird
0
0

What is wrong with this code snippet for locale switching?

medium📝 Debug Q7 of 15
Angular - Internationalization and Accessibility
What is wrong with this code snippet for locale switching?
import { LOCALE_ID } from '@angular/core';

providers: [
  { provide: LOCALE_ID, useValue: 'en-US' },
  { provide: LOCALE_ID, useValue: 'fr-FR' }
]
ALocale IDs must be uppercase, so 'fr-FR' is invalid.
BThe useValue must be a function returning the locale string.
CLOCALE_ID cannot be provided in providers array.
DMultiple providers for LOCALE_ID cause a conflict; only one should be provided.
Step-by-Step Solution
Solution:
  1. Step 1: Check provider array for duplicates

    Providing LOCALE_ID twice causes conflict; Angular uses the last one but this is bad practice.
  2. Step 2: Validate other options

    Locale IDs are case-insensitive; LOCALE_ID can be provided; useValue is a value, not function.
  3. Final Answer:

    Multiple providers for LOCALE_ID cause a conflict; only one should be provided. -> Option D
  4. Quick Check:

    Only one LOCALE_ID provider allowed [OK]
Quick Trick: Provide LOCALE_ID only once to avoid conflicts [OK]
Common Mistakes:
  • Providing LOCALE_ID multiple times
  • Thinking locale IDs must be uppercase
  • Using functions instead of values for useValue

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Angular Quizzes