Search⌘ K
AI Features

Benefits of Three Levels of Injectors

Explore how Angular's injector levels help isolate services for specific parts of an app, promoting clear separation of concerns. Understand how this isolation supports tree shaking to remove unused services, resulting in smaller, faster applications. Learn about the providedIn property that connects services to modules and facilitates efficient dependency management.

Isolation of concerns

Well, having the ability to set that a class can be injected at different levels allows us to create certain levels of isolation. We can, as we briefly discussed in the @Component Injector section, set it so that a service can only be injected at a component level or is only available at a certain module level.

This means we can create specialized services that perform one task, and are only needed in one place, if our Angular application needs to provide some business logic that is critical to the application but is ...