Creates an injector function that can be used for retrieving services as well as for dependency injection (see dependency injection).
Angular creates an injector automatically for the root scope and it is available as the
$service
property. Creating an injector doesn't automatically
create all of the $eager
services
. You have to call injector.eager()
to initialize them.
angular.injector([factoryScope][, factories][, instanceCache]);
factoryScope(optional={}) – {Object} –
The this
for the service factory function.
factories(optional=angular.service) – {Object.<string, function()>} –
Map of the service factory functions.
instanceCache(optional={}) – {Object.<string, function()>} –
Place where instances of services are
saved for reuse. Can also be used to override services specified by serviceFactory
(useful in tests).
{function()}
– Injector function:
injector(serviceName)
:
serviceName
- {string=}
- Name of the service to retrieve.The injector function also has these properties:
invoke
property which can be used to invoke methods with dependency-injected arguments.
injector.invoke(self, fn, curryArgs)
self
- The "this
" to be used when invoking the function.fn
- The function to be invoked. The function may have the $inject
property that
lists the set of arguments which should be auto-injected.
(see dependency injection).curryArgs(array)
- Optional array of arguments to pass to the function
invocation after the injection arguments (also known as curry arguments or currying).eager
property which is used to initialize the eager services.
injector.eager()