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

Function lookupTokenUsingModuleInjector

packages/core/src/render3/di.ts:408–440  ·  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

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