Injecting services in the component tree
@Component decorator has a
providers property similar to the
@NgModule decorator to register services with a component injector. A service that registers with the component injector can serve two purposes:
- It can be shared with the child components that provide the service.
- It can create multiple copies of the service every time the component that provides the service is rendered.
In the following sections, we'll learn how to apply each approach.