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

Function enterDI

packages/core/src/render3/state.ts:575–621  ·  view source on GitHub ↗
(lView: LView, tNode: TNode, flags: InternalInjectFlags)

Source from the content-addressed store, hash-verified

573 * - If `false` than this call failed and we should NOT call `leaveDI`
574 */
575export function enterDI(lView: LView, tNode: TNode, flags: InternalInjectFlags) {
576 ngDevMode && assertLViewOrUndefined(lView);
577
578 if (flags & InternalInjectFlags.SkipSelf) {
579 ngDevMode && assertTNodeForTView(tNode, lView[TVIEW]);
580
581 let parentTNode = tNode as TNode | null;
582 let parentLView = lView;
583
584 while (true) {
585 ngDevMode && assertDefined(parentTNode, 'Parent TNode should be defined');
586 parentTNode = parentTNode!.parent as TNode | null;
587 if (parentTNode === null && !(flags & InternalInjectFlags.Host)) {
588 parentTNode = getDeclarationTNode(parentLView);
589 if (parentTNode === null) break;
590
591 // In this case, a parent exists and is definitely an element. So it will definitely
592 // have an existing lView as the declaration view, which is why we can assume it's defined.
593 ngDevMode && assertDefined(parentLView, 'Parent LView should be defined');
594 parentLView = parentLView[DECLARATION_VIEW]!;
595
596 // In Ivy there are Comment nodes that correspond to ngIf and NgFor embedded directives
597 // We want to skip those and look only at Elements and ElementContainers to ensure
598 // we're looking at true parent nodes, and not content or other types.
599 if (parentTNode.type & (TNodeType.Element | TNodeType.ElementContainer)) {
600 break;
601 }
602 } else {
603 break;
604 }
605 }
606 if (parentTNode === null) {
607 // If we failed to find a parent TNode this means that we should use module injector.
608 return false;
609 } else {
610 tNode = parentTNode;
611 lView = parentLView;
612 }
613 }
614
615 ngDevMode && assertTNodeForLView(tNode, lView);
616 const lFrame = (instructionState.lFrame = allocLFrame());
617 lFrame.currentTNode = tNode;
618 lFrame.lView = lView;
619
620 return true;
621}
622
623/**
624 * Swap the current lView with a new lView.

Callers 2

getNodeInjectableFunction · 0.90

Calls 6

assertLViewOrUndefinedFunction · 0.90
assertTNodeForTViewFunction · 0.90
assertDefinedFunction · 0.90
assertTNodeForLViewFunction · 0.90
getDeclarationTNodeFunction · 0.85
allocLFrameFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…