MCPcopy
hub / github.com/angular/angular / lookupTokenUsingModuleInjector

Function lookupTokenUsingModuleInjector

packages/core/src/render3/di.ts:407–439  ·  view source on GitHub ↗

* Returns the value associated to the given token from the ModuleInjector or throws exception * * @param lView The `LView` that contains the `tNode` * @param token The token to look for * @param flags Injection flags * @param notFoundValue The value to return when the injection flags is `Intern

(
  lView: LView,
  token: ProviderToken<T>,
  flags: InternalInjectFlags,
  notFoundValue?: any,
)

Source from the content-addressed store, hash-verified

405 * @returns the value from the injector or throws an exception
406 */
407function lookupTokenUsingModuleInjector<T>(
408 lView: LView,
409 token: ProviderToken<T>,
410 flags: InternalInjectFlags,
411 notFoundValue?: any,
412): T | null {
413 if (flags & InternalInjectFlags.Optional && notFoundValue === undefined) {
414 // This must be set or the NullInjector will throw for optional deps
415 notFoundValue = null;
416 }
417
418 if ((flags & (InternalInjectFlags.Self | InternalInjectFlags.Host)) === 0) {
419 const moduleInjector = lView[INJECTOR];
420 // switch to `injectInjectorOnly` implementation for module injector, since module injector
421 // should not have access to Component/Directive DI scope (that may happen through
422 // `directiveInject` implementation)
423 const previousInjectImplementation = setInjectImplementation(undefined);
424 try {
425 if (moduleInjector) {
426 return (moduleInjector as BackwardsCompatibleInjector).get(
427 token,
428 notFoundValue,
429 flags & InternalInjectFlags.Optional,
430 );
431 } else {
432 return injectRootLimpMode(token, notFoundValue, flags & InternalInjectFlags.Optional);
433 }
434 } finally {
435 setInjectImplementation(previousInjectImplementation);
436 }
437 }
438 return notFoundValueOrThrow<T>(notFoundValue, token, flags);
439}
440
441/**
442 * Returns the value associated to the given token from the NodeInjectors => ModuleInjector.

Callers 2

getOrCreateInjectableFunction · 0.85

Calls 4

setInjectImplementationFunction · 0.90
injectRootLimpModeFunction · 0.90
notFoundValueOrThrowFunction · 0.85
getMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…