We are already familiar with the mechanism of DI registration in Angular, where we register a dependency at the global level by adding it to any module declaration.
Or we can do it at a component level using the providers
property on the @Component
decorator:
providers:[WorkoutHistoryTracker, LocalStorage]
Note
Just to avoid confusion, we are now talking about injecting dependencies other than directive/component objects. Directives/components are registered in the declarations
array of a module before they can be injected using decorator hints such as @Query
, @ViewChild
, @ViewChildren
, and a few others.
Dependencies registered at the component level are available for its view children and content children and their descendants.
Note
Before we proceed, we hope that the distinction between view and content children is crystal clear to everyone. If in doubt, refer to the Content children and view children section again.
Let's take an example from Chapter 2...