MCPcopy Index your code
hub / github.com/angular/angular / getOrCreateInjectable

Function getOrCreateInjectable

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

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

Callers 2

ɵɵdirectiveInjectFunction · 0.90
getMethod · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…