In Angular's dependency injection, what is the difference between a service provided in 'root' and one provided in a module?

  • Services provided in 'root' are lazy-loaded, while those in a module are eager-loaded
  • Services provided in 'root' are singletons, while those provided in a module are scoped to that module
  • Services provided in 'root' cannot have dependencies, while those in a module can
  • Services provided in 'root' have wider accessibility, while those in a module are private
When a service is provided in the 'root' of an Angular application, it becomes a singleton. This means there's only one instance of the service for the entire application. Services provided in a module are scoped to that module, creating a new instance for each module that imports it.
Add your answer
Loading...

Leave a comment

Your email address will not be published. Required fields are marked *