fix(ivy): properly insert views before ng-container with injected ViewContainerRef (#33853)
PR Close #33853
This commit is contained in:
parent
e698d355c1
commit
6bf2531b19
|
@ -682,7 +682,6 @@ function getFirstNativeNode(lView: LView, tNode: TNode | null): RNode|null {
|
|||
TNodeType.IcuContainer, TNodeType.Projection);
|
||||
|
||||
const tNodeType = tNode.type;
|
||||
|
||||
if (tNodeType === TNodeType.Element) {
|
||||
return getNativeByTNode(tNode, lView);
|
||||
} else if (tNodeType === TNodeType.Container) {
|
||||
|
@ -692,7 +691,12 @@ function getFirstNativeNode(lView: LView, tNode: TNode | null): RNode|null {
|
|||
if (elIcuContainerChild !== null) {
|
||||
return getFirstNativeNode(lView, elIcuContainerChild);
|
||||
} else {
|
||||
return getNativeByTNode(tNode, lView);
|
||||
const rNodeOrLContainer = lView[tNode.index];
|
||||
if (isLContainer(rNodeOrLContainer)) {
|
||||
return getBeforeNodeForView(-1, rNodeOrLContainer);
|
||||
} else {
|
||||
return unwrapRNode(rNodeOrLContainer);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
const componentView = lView[DECLARATION_COMPONENT_VIEW];
|
||||
|
|
|
@ -578,5 +578,37 @@ describe('view insertion', () => {
|
|||
expect(fixture.nativeElement.textContent).toBe('container start|test|container end|click');
|
||||
});
|
||||
|
||||
it('should properly insert before views in a ViewContainerRef injected on ng-container', () => {
|
||||
@Component({
|
||||
selector: 'app-root',
|
||||
template: `
|
||||
<ng-template #parameterListItem let-parameter="parameter">
|
||||
{{parameter}}
|
||||
</ng-template>
|
||||
<ng-container *ngFor="let parameter of items;"
|
||||
[ngTemplateOutlet]="parameterListItem"
|
||||
[ngTemplateOutletContext]="{parameter:parameter}">
|
||||
</ng-container>
|
||||
`
|
||||
})
|
||||
class AppComponent {
|
||||
items = [1];
|
||||
}
|
||||
|
||||
TestBed.configureTestingModule({
|
||||
declarations: [AppComponent],
|
||||
imports: [CommonModule],
|
||||
});
|
||||
|
||||
const fixture = TestBed.createComponent(AppComponent);
|
||||
fixture.detectChanges();
|
||||
expect(fixture.nativeElement.textContent.trim()).toContain('1');
|
||||
|
||||
fixture.componentInstance.items = [2, 1];
|
||||
fixture.detectChanges();
|
||||
|
||||
expect(fixture.nativeElement.textContent.trim()).toContain('2 1');
|
||||
});
|
||||
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue