Consider an Angular service provided in root scope. If you inject this service into two different components, how many instances of the service will be created?
Think about the providedIn: 'root' meaning in Angular services.
Services provided in root scope are singleton across the entire app. So only one instance is created and shared.
If a service is provided in a feature module (not root), and two components from that module inject it, how many instances of the service exist?
Consider how Angular creates service instances for modules.
Services provided in a module are singleton within that module. All components in that module share the same instance.
Given a service provided in a component's providers array, what happens when two instances of that component are created?
Think about how component-level providers work in Angular.
When a service is provided in a component, each component instance gets a new service instance. They do not share it.
Which of the following is the correct way to provide a service in an Angular module?
Remember where Angular expects services to be listed in a module.
Services must be listed in the providers array to be injectable in that module.
You have a service provided in root scope. However, when you lazy load two different modules that inject this service, you notice two separate instances are created. What is the most likely cause?
Check if the service is accidentally provided in multiple places.
If a service is provided in root but also listed in providers of lazy loaded modules, Angular creates separate instances per module.