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

Function getClosestRElement

packages/core/src/render3/node_manipulation.ts:533–579  ·  view source on GitHub ↗
(
  tView: TView,
  tNode: TNode | null,
  lView: LView,
)

Source from the content-addressed store, hash-verified

531 * @returns `null` if the `RElement` can't be determined at this time (no parent / projection)
532 */
533export function getClosestRElement(
534 tView: TView,
535 tNode: TNode | null,
536 lView: LView,
537): RElement | null {
538 let parentTNode: TNode | null = tNode;
539 // Skip over element and ICU containers as those are represented by a comment node and
540 // can't be used as a render parent. Also skip let declarations since they don't have a
541 // corresponding DOM node at all.
542 while (
543 parentTNode !== null &&
544 parentTNode.type & (TNodeType.ElementContainer | TNodeType.Icu | TNodeType.LetDeclaration)
545 ) {
546 tNode = parentTNode;
547 parentTNode = tNode.parent;
548 }
549
550 // If the parent tNode is null, then we are inserting across views: either into an embedded view
551 // or a component view.
552 if (parentTNode === null) {
553 // We are inserting a root element of the component view into the component host element and
554 // it should always be eager.
555 return lView[HOST];
556 } else {
557 ngDevMode && assertTNodeType(parentTNode, TNodeType.AnyRNode | TNodeType.Container);
558 if (isComponentHost(parentTNode)) {
559 ngDevMode && assertTNodeForLView(parentTNode, lView);
560 const {encapsulation} = tView.data[
561 parentTNode.directiveStart + parentTNode.componentOffset
562 ] as ComponentDef<unknown>;
563 // We've got a parent which is an element in the current view. We just need to verify if the
564 // parent element is not a component. Component's content nodes are not inserted immediately
565 // because they will be projected, and so doing insert at this point would be wasteful.
566 // Since the projection would then move it to its final destination. Note that we can't
567 // make this assumption when using the Shadow DOM, because the native projection placeholders
568 // (<content> or <slot>) have to be in place as elements are being inserted.
569 if (
570 encapsulation === ViewEncapsulation.None ||
571 encapsulation === ViewEncapsulation.Emulated
572 ) {
573 return null;
574 }
575 }
576
577 return getNativeByTNode(parentTNode, lView) as RElement;
578 }
579}
580
581/**
582 * Find a node in front of which `currentTNode` should be inserted.

Callers 2

ɵɵi18nStartFunction · 0.90
getParentRElementFunction · 0.85

Calls 4

assertTNodeTypeFunction · 0.90
isComponentHostFunction · 0.90
assertTNodeForLViewFunction · 0.90
getNativeByTNodeFunction · 0.90

Tested by

no test coverage detected