MCPcopy Create free account
hub / github.com/angular/angular / inject

Function inject

packages/core/primitives/di/src/injector.ts:41–53  ·  view source on GitHub ↗
(
  token: InjectionToken<T> | Constructor<T>,
  options?: unknown,
)

Source from the content-addressed store, hash-verified

39
40export function inject<T>(token: InjectionToken<T> | Constructor<T>): T;
41export function inject<T>(
42 token: InjectionToken<T> | Constructor<T>,
43 options?: unknown,
44): T | NotFound {
45 const currentInjector = getCurrentInjector();
46 if (!currentInjector) {
47 throw new Error('Current injector is not set.');
48 }
49 if (!(token as InjectionToken<T>).ɵprov) {
50 throw new Error('Token is not an injectable');
51 }
52 return currentInjector.retrieve(token as InjectionToken<T>, options);
53}

Callers 1

Calls 2

getCurrentInjectorFunction · 0.85
retrieveMethod · 0.65

Tested by

no test coverage detected