Class InjectorAbstract

Concrete injectors implement this interface. Injectors are configured with providers that associate dependencies of various types with injection tokens.

See

Usage Notes

The following example creates a service injector instance.

{@example core/di/ts/provider_spec.ts region='ConstructorProvider'}

Usage example

{@example core/di/ts/injector_spec.ts region='Injector'}

Injector returns itself when given Injector as a token:

{@example core/di/ts/injector_spec.ts region='injectInjector'}

Public Api

Hierarchy

  • Injector

Implemented by

Constructors

Properties

NULL: Injector = ...
THROW_IF_NOT_FOUND: {} = THROW_IF_NOT_FOUND

Type declaration

    __NG_ELEMENT_ID__: number = -1

    Nocollapse

    Methods

    • Retrieves an instance from the injector based on the provided token.

      Throws

      When the notFoundValue is undefined or Injector.THROW_IF_NOT_FOUND.

      Type Parameters

      • T

      Parameters

      Returns T

      The instance from the injector if defined, otherwise the notFoundValue.

    • Creates a new injector instance that provides one or more dependencies, according to a given type or types of StaticProvider.

      Parameters

      • options: {
            name?: string;
            parent?: Injector;
            providers: StaticProvider[];
        }

        An object with the following properties:

        • providers: An array of providers of the StaticProvider type.
        • parent: (optional) A parent injector.
        • name: (optional) A developer-defined identifying name for the new injector.

      Returns Injector

      The new injector instance.

    Generated using TypeDoc