Chapter 12Dependency Injection In AngularJS

Dependency Injection (DI) is one of the best features of AngularJS. It makes our lives easier by letting us write loosely coupled and easily testable components. The DI framework's in charge of creating components, resolving their dependencies, and passing them to other components when requested. You've already seen many examples of Dependency Injection. This chapter covers two core AngularJS services called $provide and $injector that work in the background to make Dependency Injection possible.

A Brief Recap

Components may obtain their dependencies in the following two ways:

  1. By invoking new on a constructor function to obtain their dependency themselves.

  2. By using a global variable to look up dependencies. ...

Get AngularJS: Novice to Ninja now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.