Managing the dependencies
In Angular, the framework determines what dependencies a specific class has and then injects those dependencies into the class at the time of object creation. So, taking from the above example, when Angular is creating an object of the Trello service class, it checks the constructor signature and identifies the dependencies that the Trello service needs.
In our case, it's only one, the HTTP module. Here Angular checks where the HTTP module resides, which it finds out from the definition in the app.module file. It then either creates a new instance or uses the existing instance and passes that to the Trello service constructor.
This allows us to not have the responsibility of identifying the dependency and creating ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access