UNPKG

angular2

Version:

Angular 2 - a web framework for modern web apps

33 lines (32 loc) 1.28 kB
import { CONST_EXPR } from 'angular2/src/facade/lang'; import { unimplemented } from 'angular2/src/facade/exceptions'; const _THROW_IF_NOT_FOUND = CONST_EXPR(new Object()); export const THROW_IF_NOT_FOUND = _THROW_IF_NOT_FOUND; export class Injector { /** * Retrieves an instance from the injector based on the provided token. * If not found: * - Throws {@link NoProviderError} if no `notFoundValue` that is not equal to * Injector.THROW_IF_NOT_FOUND is given * - Returns the `notFoundValue` otherwise * * ### Example ([live demo](http://plnkr.co/edit/HeXSHg?p=preview)) * * ```typescript * var injector = ReflectiveInjector.resolveAndCreate([ * provide("validToken", {useValue: "Value"}) * ]); * expect(injector.get("validToken")).toEqual("Value"); * expect(() => injector.get("invalidToken")).toThrowError(); * ``` * * `Injector` returns itself when given `Injector` as a token. * * ```typescript * var injector = ReflectiveInjector.resolveAndCreate([]); * expect(injector.get(Injector)).toBe(injector); * ``` */ get(token, notFoundValue) { return unimplemented(); } } Injector.THROW_IF_NOT_FOUND = _THROW_IF_NOT_FOUND;