export class Injector
export class Injector
exported from angular2/core defined in angular2/src/core/di/injector.ts (line 393)
A dependency injection container used for instantiating objects and resolving dependencies.
An Injector
is a replacement for a new
operator, which can automatically resolve the
constructor dependencies.
In typical use, application code asks for the dependencies in the constructor and they are
resolved by the Injector
.
Example (live demo)
The following example creates an Injector
configured to create Engine
and Car
.
Notice, we don't use the new
operator because we explicitly want to have the Injector
resolve all of the object's dependencies automatically.
Constructor
constructor(_proto: any, _parent?: Injector, _depProvider?: any, _debugContext?: Function)
constructor(_proto: any, _parent?: Injector, _depProvider?: any, _debugContext?: Function)
Private
Members
get(token: any) : any
get(token: any) : any
Retrieves an instance from the injector based on the provided token.
Throws NoProviderError
if not found.
(live demo)
Injector
returns itself when given Injector
as a token.
getOptional(token: any) : any
getOptional(token: any) : any
Retrieves an instance from the injector based on the provided token. Returns null if not found.
(live demo)
Injector
returns itself when given Injector
as a token.
parent : Injector
parent : Injector
Parent of this injector.
(live demo)
resolveAndCreateChild(providers: Array<Type | Provider | any[]>) : Injector
resolveAndCreateChild(providers: Array<Type | Provider | any[]>) : Injector
Resolves an array of providers and creates a child injector from those providers.
The passed-in providers can be an array of Type
, Provider
,
or a recursive array of more providers.
(live demo)
This function is slower than the corresponding createChildFromResolved
because it needs to resolve the passed-in providers first.
See Injector
and Injector
.
createChildFromResolved(providers: ResolvedProvider[]) : Injector
createChildFromResolved(providers: ResolvedProvider[]) : Injector
Creates a child injector from previously resolved providers.
This API is the recommended way to construct injectors in performance-sensitive parts.
(live demo)
resolveAndInstantiate(provider: Type | Provider) : any
resolveAndInstantiate(provider: Type | Provider) : any
Resolves a provider and instantiates an object in the context of the injector.
The created object does not get cached by the injector.
(live demo)
instantiateResolved(provider: ResolvedProvider) : any
instantiateResolved(provider: ResolvedProvider) : any
Instantiates an object using a resolved provider in the context of the injector.
The created object does not get cached by the injector.
(live demo)
displayName : string
displayName : string
Not Yet Documented
toString() : string
toString() : string
Not Yet Documented