Angular & Signals (283 Qs)•Part 9: NgModules, Providers, NgZone & Injector Hierarchies (213 - 255)
Can I share services using modules?
No, it is not recommended to share services by importing module. i.e Import modules when you want to use directives, pipes, and components only. The best approach to get a hold of shared services is through 'Angular dependency injection' because importing a module will result in a new service instance.
Practical Code Example
text
// Sharing services using modules:
// Services should generally use providedIn: 'root' instead of being exported in SharedModule
// to prevent accidental duplicate service instances when lazy loading.