diff --git a/packages/compiler/src/render3/r3_view_compiler.ts b/packages/compiler/src/render3/r3_view_compiler.ts index eb6f3bef3c..662053033f 100644 --- a/packages/compiler/src/render3/r3_view_compiler.ts +++ b/packages/compiler/src/render3/r3_view_compiler.ts @@ -575,15 +575,20 @@ class TemplateDefinitionBuilder implements TemplateAstVisitor, LocalResolver { // TemplateAstVisitor visitNgContent(ngContent: NgContentAst) { - const info = this._contentProjections.get(ngContent) !; - info || - error(`Expected ${ngContent.sourceSpan} to be included in content projection collection`); - const slot = this.allocateDataSlot(); - const parameters = [o.literal(slot), o.literal(this._projectionDefinitionIndex)]; - if (info.index !== 0) { - parameters.push(o.literal(info.index)); + const info = this._contentProjections.get(ngContent); + if (!info) { + error(`Expected ${ngContent.sourceSpan} to be included in content projection collection`); + } else { + const slot = this.allocateDataSlot(); + const parameters = [ + o.literal(slot), + o.literal(this._projectionDefinitionIndex), + ]; + if (info.index !== 0) { + parameters.push(o.literal(info.index)); + } + this.instruction(this._creationMode, ngContent.sourceSpan, R3.projection, ...parameters); } - this.instruction(this._creationMode, ngContent.sourceSpan, R3.projection, ...parameters); } // TemplateAstVisitor diff --git a/packages/core/src/render3/instructions.ts b/packages/core/src/render3/instructions.ts index a330ad78bd..a32f34badd 100644 --- a/packages/core/src/render3/instructions.ts +++ b/packages/core/src/render3/instructions.ts @@ -1722,32 +1722,28 @@ function appendToProjectionNode( * @param nodeIndex * @param localIndex - index under which distribution of projected nodes was memorized * @param selectorIndex - 0 means without any selector - * @param attrs - attributes attached to the ng-content node, if present */ -export function projection( - nodeIndex: number, localIndex: number, selectorIndex: number = 0, attrs?: string[]): void { +export function projection(nodeIndex: number, localIndex: number, selectorIndex: number = 0): void { const node = createLNode(nodeIndex, LNodeType.Projection, null, {head: null, tail: null}); - if (node.tNode == null) { - node.tNode = createTNode(null, attrs || null, null); - } - - isParent = false; // self closing + // `` has no content + isParent = false; const currentParent = node.parent; // re-distribution of projectable nodes is memorized on a component's view level const componentNode = findComponentHost(currentView); - - // make sure that nodes to project were memorized - const nodesForSelector = componentNode.data !.data ![localIndex][selectorIndex]; + const componentLView = componentNode.data !; + const nodesForSelector = componentLView.data ![localIndex][selectorIndex]; // build the linked list of projected nodes: for (let i = 0; i < nodesForSelector.length; i++) { const nodeToProject = nodesForSelector[i]; if (nodeToProject.type === LNodeType.Projection) { + // Reprojecting a projection -> append the list of previously projected nodes const previouslyProjected = (nodeToProject as LProjectionNode).data; appendToProjectionNode(node, previouslyProjected.head, previouslyProjected.tail); } else { + // Projecting a single node appendToProjectionNode( node, nodeToProject as LTextNode | LElementNode | LContainerNode, nodeToProject as LTextNode | LElementNode | LContainerNode);