MCPcopy Create free account
hub / github.com/angular/angular / ɵɵdirectiveInject

Function ɵɵdirectiveInject

packages/core/src/render3/instructions/di.ts:45–66  ·  view source on GitHub ↗
(
  token: ProviderToken<T>,
  flags = InternalInjectFlags.Default,
)

Source from the content-addressed store, hash-verified

43export function ɵɵdirectiveInject<T>(token: ProviderToken<T>): T;
44export function ɵɵdirectiveInject<T>(token: ProviderToken<T>, flags: number): T;
45export function ɵɵdirectiveInject<T>(
46 token: ProviderToken<T>,
47 flags = InternalInjectFlags.Default,
48): T | null {
49 const lView = getLView();
50 // Fall back to inject() if view hasn't been created. This situation can happen in tests
51 // if inject utilities are used before bootstrapping.
52 if (lView === null) {
53 // Verify that we will not get into infinite loop.
54 ngDevMode && assertInjectImplementationNotEqual(ɵɵdirectiveInject);
55 return ɵɵinject(token, flags);
56 }
57 const tNode = getCurrentTNode();
58 const value = getOrCreateInjectable<T>(
59 tNode as TDirectiveHostNode,
60 lView,
61 resolveForwardRef(token),
62 flags,
63 );
64 ngDevMode && emitInjectEvent(token as Type<unknown>, value, flags);
65 return value;
66}
67
68/**
69 * Throws an error indicating that a factory function could not be generated by the compiler for a

Callers

nothing calls this directly

Calls 7

getLViewFunction · 0.90
ɵɵinjectFunction · 0.90
getCurrentTNodeFunction · 0.90
getOrCreateInjectableFunction · 0.90
resolveForwardRefFunction · 0.90
emitInjectEventFunction · 0.90

Tested by

no test coverage detected