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. Creation of the injector automatically creates
all of the $eager
services
.
angular.injector([factoryScope][, factories][, instanceCache]);
factoryScope(optional={}) – {Object} –
this
for the service factory function.
factories(optional=angular.service) – {Object.<string, function()>} –
Map of 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
- "this
" to be used when invoking the function.fn
- the function to be invoked. The function may have the $inject
property which
lists the set of arguments which should be auto injected
(see dependency injection).curryArgs(array)
- optional array of arguments to pass to 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()