Injector
Direct Subclass:
A dependency injector for resolving dependencies. Injectors are hierarchicle.
Example:
const injector = new Injector([
  { provide: 'test', useValue: 'blorg' },
  { provide: 'factory', useFactory: () => 'BOOM' },
  { provide: 'myClass', useClass: MyClass },
  MyClass
]);
injector.get('test'); // => 'blorg';
injector.get('factory'); // => 'BOOM';
injector.get('myClass'); // => instanceof MyClass;
injector.get(MyClass); // => instanceof MyClass;
    Static Method Summary
| Static Public Methods | ||
| public static | 
       fromInjectable(injectable: Type<any>, providers: ProviderArg[], parent: Injector): Injector Creates a new injector from an annotated injectable Class.  | 
    |
| public static | 
       resolveInjectables(injectable: *): *[]  | 
    |
Constructor Summary
| Public Constructor | ||
| public | 
       constructor(providers: ProviderArg[], _parent: Injector | null) Creates an instance of Injector.  | 
    |
Method Summary
| Public Methods | ||
| public | 
       get(token: *, defaultValue: *, metadata: InjectionMetadata): * Gets a dependecy from the provided token.  | 
    |
| public | 
       getDependencies(metadata: *): *  | 
    |
| public | 
       instantiate(Ref: *, d: ...*): *  | 
    |
| public | 
       invoke(fn: *, providers: *): *  | 
    |
| public | 
       registerProvider(provider: ProviderArg) Registers a provider with the injector.  | 
    |
| public | 
       resolveAndCreateChild(providers: ProviderArg[]): Injector Creates a new injector with the given providers and sets this injector as it's parent.  | 
    |
| public | 
       resolveAndInstantiate(provider: *): T Resolves the given provider with this injector.  | 
    |
| public | 
      
       Programmatically set the parent injector.  | 
    |
Static Public Methods
public static fromInjectable(injectable: Type<any>, providers: ProviderArg[], parent: Injector): Injector source
Creates a new injector from an annotated injectable Class. See Injectable for more details.
Params:
| Name | Type | Attribute | Description | 
| injectable | Type<any> | ||
| providers | ProviderArg[] | 
  | 
      |
| parent | Injector | 
  | 
      
public static resolveInjectables(injectable: *): *[] source
Params:
| Name | Type | Attribute | Description | 
| injectable | * | 
Return:
| *[] | 
Public Constructors
public constructor(providers: ProviderArg[], _parent: Injector | null) source
Creates an instance of Injector.
Params:
| Name | Type | Attribute | Description | 
| providers | ProviderArg[] | 
  | 
      List of providers for this injector.  | 
    
| _parent | Injector | null | 
  | 
      A parent injector.  | 
    
Public Methods
public get(token: *, defaultValue: *, metadata: InjectionMetadata): * source
Gets a dependecy from the provided token.
Params:
| Name | Type | Attribute | Description | 
| token | * | ||
| defaultValue | * | 
  | 
      |
| metadata | InjectionMetadata | 
  | 
      
Return:
| * | 
public getDependencies(metadata: *): * source
Params:
| Name | Type | Attribute | Description | 
| metadata | * | 
Return:
| * | 
public instantiate(Ref: *, d: ...*): * source
Params:
| Name | Type | Attribute | Description | 
| Ref | * | ||
| d | ...* | 
Return:
| * | 
public invoke(fn: *, providers: *): * source
Params:
| Name | Type | Attribute | Description | 
| fn | * | ||
| providers | * | 
Return:
| * | 
public registerProvider(provider: ProviderArg) source
Registers a provider with the injector.
Params:
| Name | Type | Attribute | Description | 
| provider | ProviderArg | 
public resolveAndCreateChild(providers: ProviderArg[]): Injector source
Creates a new injector with the given providers and sets this injector as it's parent.
Params:
| Name | Type | Attribute | Description | 
| providers | ProviderArg[] | 
  | 
      
public resolveAndInstantiate(provider: *): T source
Resolves the given provider with this injector.
Params:
| Name | Type | Attribute | Description | 
| provider | * | 
Return:
| T |