Using Dependency Injection
Dependency Injection is pervasive throughout AngularJS. You can use it when defining components or when providing
run
and config
blocks for a module.- Services, directives, filters, and animations are defined by an injectable factory method or constructor function, and can be injected with "services", "values", and "constants" as dependencies.
- Controllers are defined by a constructor function, which can be injected with any of the "service" and "value" as dependencies, but they can also be provided with "special dependencies". See Controllersbelow for a list of these special dependencies.
- The
run
method accepts a function, which can be injected with "services", "values" and, "constants" as dependencies. Note that you cannot inject "providers" intorun
blocks. - The
config
method accepts a function, which can be injected with "providers" and "constants" as dependencies. Note that you cannot inject "services" or "values" into configuration. - The
provider
method can only be injected with other "providers". However, only those that have been registered beforehand can be injected. This is different from services, where the order of registration does not matter.
0 comments:
Post a Comment