angular.injector

Description

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.

Usage

angular.injector([factoryScope][, factories][, instanceCache]);

Parameters

Returns

{function()}

Injector function:

  • injector(serviceName):
    • serviceName - {string=} - name of the service to retrieve.

The injector function also has these properties:

  • an 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).
  • an eager property which is used to initialize the eager services. injector.eager()