Creates an inject function that can be used for dependency injection. (See dependency injection)
The inject function can be used for retrieving service instances or for calling any function
which has the $inject property so that the services can be automatically provided. Angular
creates an injection function automatically for the root scope and it is available as
$service
.
angular.injector([providerScope][, providers][, cache]);
providerScope(optional={}) – {Object} –
provider's this
providers(optional=angular.service) – {Object.<string, function()>} –
Map of provider (factory) function.
cache(optional={}) – {Object.<string, function()>} –
Place where instances are saved for reuse. Can
also be used to override services speciafied by providers
(useful in tests).
{function()}
– Injector function: function(value, scope, args...)
:
value
- {string|array|function}
scope(optional=rootScope)
- optional function "this
" when value
is type function
.args(optional)
- optional set of arguments to pass to function after injection arguments.
(also known as curry arguments or currying).function(value, scope, args...)
The injector function return value depended on the type of value
argument:
string
: return an instance for the injection key.array
of keys: returns an array of instances for those keys. (see string
above.)function
: look at $inject
property of function to determine instances to inject
and then call the function with instances and scope
. Any additional arguments
(args
) are appended to the function arguments.none
: initialize eager providers.