Skip to content
Permalink
Browse files

fix(ivy): properly insert views before ng-container with injected Vie…

…wContainerRef (#33853)

PR Close #33853
  • Loading branch information
pkozlowski-opensource authored and alxhub committed Nov 15, 2019
1 parent 839ac3c commit c7a3694eb9659797ea20685a43ff4e335425bacd
@@ -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');
});

});
});

0 comments on commit c7a3694

Please sign in to comment.
You can’t perform that action at this time.