Provider placement determines which injector creates a service and which descendants share it. Local providers can deliberately create isolated instances.
Before you start
You should understand a component’s class, template and dependencies. Follow both the framework lifecycle and the ownership of each value or resource. Apply examples inside an Angular application; the surrounding application configuration and imports depend on the feature being demonstrated.
The practical goal is to reason through this situation: Two editor components each providing DraftService receive independent drafts. Read the walkthrough first, then try the interview exercise before opening its answer. The important part is explaining the decision and its consequences, rather than remembering a definition alone.
Step-by-step walkthrough
Step 1: Choose the intended lifetime
A session should be shared application-wide; a local draft may need one instance per editor.
Step 2: Place the provider accordingly
Application-level provision shares one service within that injector scope. Component providers create descendant-local instances.
Step 3: Detect accidental duplication
Log instance identity in two consumers. A local provider can shadow a supposedly global service without changing its class name.
Worked scenario
Two editor components each providing DraftService receive independent drafts.
Editor A and editor B each providing DraftService get independent drafts. Moving the provider to their shared owner changes that relationship. This is a design decision: isolated drafts avoid interference, while a shared session enables coordinated state across routes. Provider placement determines behavior, not just injection convenience.
Common mistake
Providing a supposedly global service locally silently creates another instance.
Verify the behavior
Compare service identities across siblings, descendants and route changes. Confirm state persistence matches the intended ownership boundary.
Interview exercise
Share a session across routes.
Answer and reasoning
Place the provider in the application-level environment when one shared lifetime is intended; avoid duplicate component providers.
Continue learning
Compare the scenario with the Angular interview questions and test your understanding with the Angular MCQs. For terminology and implementation details, consult the reference material.