Implementing a Custom Provider and Injecting It into a Controller
Listing 3.3 shows how to implement dependency injection with two modules, each with a value provider and a controller. Lines 2 and 8 add the value providers. Lines 3 and 9 use dependency injection to inject the value providers into the controllers for each module.
Notice in line 6 that the definition for the myApp
module includes the myMod
module in its dependency list. This injects myMod
, including the controllerB
functionality, enclosed inside.
Listing 3.4 shows HTML that implements the myApp
module as the AngularJS application. Notice that it uses both the controllerA
and the controllerB
controllers. They can be used because the myMod
module was injected into the myApp
module. ...
Get Learning AngularJS 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.