Bird
0
0

Why does Angular require the @Injectable decorator on services that inject other services, even if they don't have constructor parameters themselves?

hard🧠 Conceptual Q10 of 15
Angular - Services and Dependency Injection
Why does Angular require the @Injectable decorator on services that inject other services, even if they don't have constructor parameters themselves?
ABecause services without constructor parameters cannot be injected otherwise.
BBecause @Injectable automatically registers the service as a component.
CBecause Angular needs metadata to generate the injector factory for the service.
DBecause @Injectable disables tree shaking for the service.
Step-by-Step Solution
Solution:
  1. Step 1: Understand role of @Injectable metadata

    @Injectable provides Angular with metadata to generate the factory needed for dependency injection.
  2. Step 2: Clarify misconceptions

    It does not register services as components, nor disables tree shaking. Services without constructor params still need metadata.
  3. Final Answer:

    Because Angular needs metadata to generate the injector factory for the service. -> Option C
  4. Quick Check:

    @Injectable provides DI metadata for factory generation [OK]
Quick Trick: Always add @Injectable for DI metadata, even if no params [OK]
Common Mistakes:
MISTAKES
  • Thinking @Injectable registers service as component
  • Assuming services without params don't need @Injectable
  • Believing @Injectable disables tree shaking

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Angular Quizzes