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

Function searchTokensOnInjector

packages/core/src/render3/di.ts:627–673  ·  view source on GitHub ↗
(
  injectorIndex: number,
  lView: LView,
  token: ProviderToken<T>,
  previousTView: TView | null,
  flags: InternalInjectFlags,
  hostTElementNode: TNode | null,
)

Source from the content-addressed store, hash-verified

625}
626
627function searchTokensOnInjector<T>(
628 injectorIndex: number,
629 lView: LView,
630 token: ProviderToken<T>,
631 previousTView: TView | null,
632 flags: InternalInjectFlags,
633 hostTElementNode: TNode | null,
634) {
635 const currentTView = lView[TVIEW];
636 const tNode = currentTView.data[injectorIndex + NodeInjectorOffset.TNODE] as TNode;
637 // First, we need to determine if view providers can be accessed by the starting element.
638 // There are two possibilities
639 const canAccessViewProviders =
640 previousTView == null
641 ? // 1) This is the first invocation `previousTView == null` which means that we are at the
642 // `TNode` of where injector is starting to look. In such a case the only time we are allowed
643 // to look into the ViewProviders is if:
644 // - we are on a component
645 // - AND the injector set `includeViewProviders` to true (implying that the token can see
646 // ViewProviders because it is the Component or a Service which itself was declared in
647 // ViewProviders)
648 isComponentHost(tNode) && includeViewProviders
649 : // 2) `previousTView != null` which means that we are now walking across the parent nodes.
650 // In such a case we are only allowed to look into the ViewProviders if:
651 // - We just crossed from child View to Parent View `previousTView != currentTView`
652 // - AND the parent TNode is an Element.
653 // This means that we just came from the Component's View and therefore are allowed to see
654 // into the ViewProviders.
655 previousTView != currentTView && (tNode.type & TNodeType.AnyRNode) !== 0;
656
657 // This special case happens when there is a @host on the inject and when we are searching
658 // on the host element node.
659 const isHostSpecialCase = flags & InternalInjectFlags.Host && hostTElementNode === tNode;
660
661 const injectableIdx = locateDirectiveOrProvider(
662 tNode,
663 currentTView,
664 token,
665 canAccessViewProviders,
666 isHostSpecialCase,
667 );
668 if (injectableIdx !== null) {
669 return getNodeInjectable(lView, currentTView, injectableIdx, tNode as TElementNode, flags);
670 } else {
671 return NOT_FOUND;
672 }
673}
674
675/**
676 * Searches for the given token among the node's directives and providers.

Callers 1

Calls 3

isComponentHostFunction · 0.90
getNodeInjectableFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…