fix(ivy): ng-content tags in re-inserted templates should walk declaration tree (#27783)

This PR assures that content projection works if an <ng-content> tag is
placed inside an <ng-template> in one component and that <ng-template>
is inserted into a different component. It fixes a bug where the
projection instruction code would walk up the insertion tree to find
selector data instead of the declaration tree.

PR Close #27783
This commit is contained in:
Kara Erickson
2018-12-20 13:30:08 -08:00
parent 3f2ebbd7ab
commit 7eb2c41fb2
4 changed files with 86 additions and 21 deletions

View File

@ -263,28 +263,16 @@ export function addAllToArray(items: any[], arr: any[]) {
* Given a current view, finds the nearest component's host (LElement).
*
* @param lView LView for which we want a host element node
* @param declarationMode indicates whether DECLARATION_VIEW or PARENT should be used to climb the
* tree.
* @returns The host node
*/
export function findComponentView(lView: LView, declarationMode?: boolean): LView {
export function findComponentView(lView: LView): LView {
let rootTNode = lView[HOST_NODE];
while (rootTNode && rootTNode.type === TNodeType.View) {
ngDevMode && assertDefined(
lView[declarationMode ? DECLARATION_VIEW : PARENT],
declarationMode ? 'lView.declarationView' : 'lView.parent');
lView = lView[declarationMode ? DECLARATION_VIEW : PARENT] !;
ngDevMode && assertDefined(lView[DECLARATION_VIEW], 'lView[DECLARATION_VIEW]');
lView = lView[DECLARATION_VIEW] !;
rootTNode = lView[HOST_NODE];
}
return lView;
}
/**
* Return the host TElementNode of the starting LView
* @param lView the starting LView.
*/
export function getHostTElementNode(lView: LView): TElementNode|null {
return findComponentView(lView, true)[HOST_NODE] as TElementNode;
}