Inject services via constructor or inject()—Angular resolves tokens from injectors.
Important interview questions and answers
- Q: Why does this matter?
A: Inject services via constructor or inject()—Angular resolves tokens from injectors.
Self-check
- Summarize Dependency injection in one sentence.
- What would you try next in the playground?
Challenge
Dependency injection hands-on
- Edit the default code.
- Click Run in browser.
- Confirm preview or terminal output.
Done when: preview or terminal matches the lesson goal.
Tip: Prefer inject(Token) in functional code and providedIn: 'root' for app-wide singletons.
Interview prep
- Why use dependency injection?
Decouple components from concrete implementations, enable testing with mocks, and centralize configuration.