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

Function getClosestRElement

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

Source from the content-addressed store, hash-verified

506 * @returns `null` if the `RElement` can't be determined at this time (no parent / projection)
507 */
508export function getClosestRElement(
509 tView: TView,
510 tNode: TNode | null,
511 lView: LView,
512): RElement | null {
513 let parentTNode: TNode | null = tNode;
514 // Skip over element and ICU containers as those are represented by a comment node and
515 // can't be used as a render parent. Also skip let declarations since they don't have a
516 // corresponding DOM node at all.
517 while (
518 parentTNode !== null &&
519 parentTNode.type & (TNodeType.ElementContainer | TNodeType.Icu | TNodeType.LetDeclaration)
520 ) {
521 tNode = parentTNode;
522 parentTNode = tNode.parent;
523 }
524
525 // If the parent tNode is null, then we are inserting across views: either into an embedded view
526 // or a component view.
527 if (parentTNode === null) {
528 // We are inserting a root element of the component view into the component host element and
529 // it should always be eager.
530 return lView[HOST];
531 } else {
532 ngDevMode && assertTNodeType(parentTNode, TNodeType.AnyRNode | TNodeType.Container);
533 if (isComponentHost(parentTNode)) {
534 ngDevMode && assertTNodeForLView(parentTNode, lView);
535 const {encapsulation} = tView.data[
536 parentTNode.directiveStart + parentTNode.componentOffset
537 ] as ComponentDef<unknown>;
538 // We've got a parent which is an element in the current view. We just need to verify if the
539 // parent element is not a component. Component's content nodes are not inserted immediately
540 // because they will be projected, and so doing insert at this point would be wasteful.
541 // Since the projection would then move it to its final destination. Note that we can't
542 // make this assumption when using the Shadow DOM, because the native projection placeholders
543 // (<content> or <slot>) have to be in place as elements are being inserted.
544 if (
545 encapsulation === ViewEncapsulation.None ||
546 encapsulation === ViewEncapsulation.Emulated
547 ) {
548 return null;
549 }
550 }
551
552 return getNativeByTNode(parentTNode, lView) as RElement;
553 }
554}
555
556/**
557 * 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