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