MCPcopy
hub / github.com/angular/angular / inject

Function inject

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

Source from the content-addressed store, hash-verified

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

Callers 1

Calls 2

getCurrentInjectorFunction · 0.85
retrieveMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…