angular.injector

Description

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.

Usage

angular.injector([providerScope][, providers][, cache]);

Parameters

Returns

{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).

Return value of 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.