Understand Angular @Injectable

InstructorPascal Precht

Share this video with your friends

Send Tweet

In order to resolve a dependency, Angular’s DI uses type annotations. To make sure these types are preserved when transpiled to ES5, TypeScript emits metadata. In this lesson we’ll explore how the @Injectable decorator ensures metadata generation for services that have their own dependencies.

Michael Sevestre
~ 8 years ago

The end result is a bit weird in my opinion. The ListComponent is the component configuring the LogService and the ConsoleService but the DataService is the one using them! This breaks all encapsulation don't you think?

Michael Sevestre
~ 8 years ago

Unless you consider the ListComponent the main file of the application where all configurations for injectable components is made. (such as the the FactoryProvider for LogDebugger). Does this mean then that this configuration is GLOBAL for all components? What happens if another component defines another FactoryProvider for LogDebugger?