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. Creating an injector doesn't automatically create all of the $eager services. You have to call injector.eager() to initialize them.

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