Why do two Angular components receive different instances of one service?
Understand the idea, explain it in your own words and use the rubric to find your next learning gap.
The idea behind the question
Angular dependency injection resolves a token through an injector hierarchy. Providing a service at a component boundary can create an instance with a narrower lifetime than a root-provided service.
Two independent editors provide the same draft service locally so their current drafts do not overwrite each other.
A practical way to learn it
Create two independent counter panels with component-scoped services, then move the provider to a shared scope and describe how the behavior changes.
Open Angular project studioThe related tool opens separately; your interview answer stays here. Written practice is self-guided, without automatic code grading.
Build an explanation you understand
- State what the concept does in plain language.
- Apply it to the example and make your assumptions explicit.
- Explain a trade-off, failure case and how you would test it.
- Distinguish your actual experience from a proposed approach.
How would you explain it?
Single-question timers reset on refresh. Full mock sessions can resume from this browser.
Strengthen your explanation
Compare reasoning, not identical wording. Reference answers describe a possible approach; replace hypothetical statements with truthful details from your own work.
One way to answer
I would inspect where the token is provided, not only where it is injected. A root-provided service is commonly shared through the root environment, while a component provider can create a separate instance for that component subtree. I would choose the lifetime to match ownership and clean up subscriptions or resources when their scope ends. Shared state must be deliberate, especially when opening multiple editors. I would test identity and state isolation across sibling instances and avoid depending on a service being global when a local provider shadows it.
What a strong explanation should cover
Tick only the points your own answer addresses. This is self-assessment, not AI scoring.
0 / 3 points self-reportedWatch out for
- Assuming every service is a singleton merely because it uses Injectable.
Now go one level deeper
- When would a shared cache belong in a broader scope?
- How could a test accidentally use a different provider from production?
Further reading
Further-reading links support learning; the reference is Sukoaa-authored, not an official employer answer key.