fix(ivy): properly insert views in front of empty views (#33647)
PR Close #33647
This commit is contained in:
parent
056236cafd
commit
05d7c575e4
@ -671,7 +671,12 @@ function getFirstNativeNode(lView: LView, tNode: TNode | null): RNode|null {
|
|||||||
const lContainer = lView[tNode.index];
|
const lContainer = lView[tNode.index];
|
||||||
if (lContainer.length > CONTAINER_HEADER_OFFSET) {
|
if (lContainer.length > CONTAINER_HEADER_OFFSET) {
|
||||||
const firstView = lContainer[CONTAINER_HEADER_OFFSET];
|
const firstView = lContainer[CONTAINER_HEADER_OFFSET];
|
||||||
return getFirstNativeNode(firstView, firstView[TVIEW].firstChild);
|
const firstTNodeOfView = firstView[TVIEW].firstChild;
|
||||||
|
if (firstTNodeOfView !== null) {
|
||||||
|
return getFirstNativeNode(firstView, firstTNodeOfView);
|
||||||
|
} else {
|
||||||
|
return lContainer[NATIVE];
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
return lContainer[NATIVE];
|
return lContainer[NATIVE];
|
||||||
}
|
}
|
||||||
|
@ -263,15 +263,7 @@ describe('view insertion', () => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
describe('before embedded view', () => {
|
describe('before embedded view', () => {
|
||||||
@Component({
|
@Component({selector: 'test-cmpt', template: ''})
|
||||||
selector: 'test-cmpt',
|
|
||||||
template: `
|
|
||||||
<ng-template #insert>insert</ng-template>
|
|
||||||
<ng-template #before>|before</ng-template>
|
|
||||||
|
|
||||||
<div><ng-template #vi="vi" viewInserting></ng-template></div>
|
|
||||||
`
|
|
||||||
})
|
|
||||||
class TestCmpt {
|
class TestCmpt {
|
||||||
@ViewChild('before', {static: true}) beforeTpl !: TemplateRef<{}>;
|
@ViewChild('before', {static: true}) beforeTpl !: TemplateRef<{}>;
|
||||||
@ViewChild('insert', {static: true}) insertTpl !: TemplateRef<{}>;
|
@ViewChild('insert', {static: true}) insertTpl !: TemplateRef<{}>;
|
||||||
@ -348,8 +340,8 @@ describe('view insertion', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should insert before a view with an empty container as the first root node', () => {
|
it('should insert before a view with an empty container as the first root node', () => {
|
||||||
expect(createAndInsertViews(`<ng-template [ngIf]="true"></ng-template>`).textContent)
|
expect(createAndInsertViews(`<ng-template [ngIf]="true"></ng-template>|before`).textContent)
|
||||||
.toBe('insert');
|
.toBe('insert|before');
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user