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

Function getOrCreateInjectable

packages/core/src/render3/di.ts:458–495  ·  view source on GitHub ↗
(
  tNode: TDirectiveHostNode | null,
  lView: LView,
  token: ProviderToken<T>,
  flags: InternalInjectFlags = InternalInjectFlags.Default,
  notFoundValue?: any,
)

Source from the content-addressed store, hash-verified

456 * @returns the value from the injector, `null` when not found, or `notFoundValue` if provided
457 */
458export function getOrCreateInjectable<T>(
459 tNode: TDirectiveHostNode | null,
460 lView: LView,
461 token: ProviderToken<T>,
462 flags: InternalInjectFlags = InternalInjectFlags.Default,
463 notFoundValue?: any,
464): T | null {
465 if (tNode !== null) {
466 // If the view or any of its ancestors have an embedded
467 // view injector, we have to look it up there first.
468 if (
469 lView[FLAGS] & LViewFlags.HasEmbeddedViewInjector &&
470 // The token must be present on the current node injector when the `Self`
471 // flag is set, so the lookup on embedded view injector(s) can be skipped.
472 !(flags & InternalInjectFlags.Self)
473 ) {
474 const embeddedInjectorValue = lookupTokenUsingEmbeddedInjector(
475 tNode,
476 lView,
477 token,
478 flags,
479 NOT_FOUND,
480 );
481 if (embeddedInjectorValue !== NOT_FOUND) {
482 return embeddedInjectorValue;
483 }
484 }
485
486 // Otherwise try the node injector.
487 const value = lookupTokenUsingNodeInjector(tNode, lView, token, flags, NOT_FOUND);
488 if (value !== NOT_FOUND) {
489 return value;
490 }
491 }
492
493 // Finally, fall back to the module injector.
494 return lookupTokenUsingModuleInjector<T>(lView, token, flags, notFoundValue);
495}
496
497/**
498 * Returns the value associated to the given token from the node injector.

Callers 3

ɵɵdirectiveInjectFunction · 0.90
ɵɵforeignComponentFunction · 0.90
getMethod · 0.85

Tested by

no test coverage detected