Bird
0
0

Identify the error in this Angular code snippet:

medium📝 Debug Q6 of 15
Angular - Server-Side Rendering
Identify the error in this Angular code snippet:
const USER_KEY = makeStateKey('user');
this.transferState.get(USER_KEY);
AUSER_KEY should be a string, not a StateKey
BMissing default value argument in get method
CmakeStateKey is not imported
DtransferState must be injected with @Inject decorator
Step-by-Step Solution
Solution:
  1. Step 1: Check get method signature

    get requires two arguments: key and defaultValue.
  2. Step 2: Identify missing argument

    The code calls get with only the key, missing defaultValue, causing a compile error.
  3. Final Answer:

    Missing default value argument in get method -> Option B
  4. Quick Check:

    get needs key and defaultValue [OK]
Quick Trick: Always provide defaultValue in get method [OK]
Common Mistakes:
  • Omitting defaultValue argument
  • Confusing key type with string
  • Assuming @Inject is mandatory for TransferState

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Angular Quizzes