Services, factories, and providers register singletons for API access and shared state.
Important interview questions and answers
- Q: Why does this matter?
A: Services, factories, and providers register singletons for API access and shared state.
Self-check
- Summarize Services and factories in one sentence.
- What would you try next in the playground?
Challenge
Services and factories hands-on
- Edit the default code.
- Click Run in browser.
- Confirm preview or terminal output.
Done when: preview or terminal matches the lesson goal.
Challenge
Increment shared service
- Click + and confirm terminal JSON increments.
- Reload and verify service state resets (no persistence).
Done when: terminal count increases on each click.
Interview prep
- Service vs factory?
service() invokes constructor with
new; factory() returns the object/function you register—both are singletons per injector.