Angular Service Injection Best Practice

Viewed 125

I am just trying to understand the best practices of Angular and here is my question regarding services injection.

Imagine we have a feature that gets all items of a list and can do some actions. So we have a service with CRUD methods. Also, we have created a separate module for this feature. What would be the best way to use this service? Should this service be singleton? What services should be singleton?

Basically, I am trying to understand what services should be injected in root, what in modules and what in components using lazy-loaded modules.

1 Answers

You can use your common/core services in the root module, or in case you need a service for the specific component you can inject service directly into the component, If you have a service that you think that service can be sharable more than one module you can create a shared module and inject service to that module.

Related