Stable Class
What it does
Injector interface
How to use
1 2 3 | <code>const injector: Injector = ...; injector.get(...); </code> |
Class Overview
1 2 3 4 5 | class Injector { staticTHROW_IF_NOT_FOUND : _THROW_IF_NOT_FOUND staticNULL : Injector get(token: any, notFoundValue?: any) : any } |
Class Description
For more details, see the Dependency Injection Guide.
Example
1 2 3 4 5 | const injector: Injector = ReflectiveInjector.resolveAndCreate([{provide: 'validToken' , useValue: 'Value' }]); expect(injector.get( 'validToken' )).toEqual( 'Value' ); expect(() => injector.get( 'invalidToken' )).toThrowError(); expect(injector.get( 'invalidToken' , 'notFound' )).toEqual( 'notFound' ); |
Injector
returns itself when given Injector
as a token:
1 2 | const injector = ReflectiveInjector.resolveAndCreate([]); expect(injector.get(Injector)).toBe(injector); |
Static Members
THROW_IF_NOT_FOUND : _THROW_IF_NOT_FOUND
NULL : Injector
Class Details
get(token: any, notFoundValue?: any) : any
Retrieves an instance from the injector based on the provided token. If not found:
- Throws NoProviderError if no
notFoundValue
that is not equal to Injector.THROW_IF_NOT_FOUND is given - Returns the
notFoundValue
otherwise ```
exported from @angular/core/index, defined in @angular/core/src/di/injector.ts
Please login to continue.