Stable
Class
Injector interface
const injector: Injector = ...; injector.get(...);
class Injector { static THROW_IF_NOT_FOUND : _THROW_IF_NOT_FOUND static NULL : Injector get(token: any, notFoundValue?: any) : any }
For more details, see the Dependency Injection Guide.
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:
const injector = ReflectiveInjector.resolveAndCreate([]); expect(injector.get(Injector)).toBe(injector);
THROW_IF_NOT_FOUND : _THROW_IF_NOT_FOUND
NULL : Injector
get(token: any, notFoundValue?: any) : any
Retrieves an instance from the injector based on the provided token. If not found:
notFoundValue
that is not equal to Injector.THROW_IF_NOT_FOUND is givennotFoundValue
otherwiseexported from @angular/core/index, defined in @angular/core/src/di/injector.ts
© 2010–2017 Google, Inc.
Licensed under the Creative Commons Attribution License 4.0.
https://v2.angular.io/docs/ts/latest/api/core/index/Injector-class.html