fix(ivy): fix issue with refreshing embedded views (#23164)

PR Close #23164
This commit is contained in:
Pawel Kozlowski 2018-04-04 14:40:06 +02:00 committed by Igor Minar
parent 3b607e60e9
commit fc813f67f4
2 changed files with 11 additions and 2 deletions

View File

@ -442,6 +442,7 @@ export function renderEmbeddedTemplate<T>(
renderer: Renderer3): LViewNode { renderer: Renderer3): LViewNode {
const _isParent = isParent; const _isParent = isParent;
const _previousOrParentNode = previousOrParentNode; const _previousOrParentNode = previousOrParentNode;
let oldView: LView;
try { try {
isParent = true; isParent = true;
previousOrParentNode = null !; previousOrParentNode = null !;
@ -456,14 +457,14 @@ export function renderEmbeddedTemplate<T>(
viewNode = createLNode(null, LNodeType.View, null, view); viewNode = createLNode(null, LNodeType.View, null, view);
cm = true; cm = true;
} }
enterView(viewNode.data, viewNode); oldView = enterView(viewNode.data, viewNode);
template(context, cm); template(context, cm);
refreshDirectives(); refreshDirectives();
refreshDynamicChildren(); refreshDynamicChildren();
} finally { } finally {
leaveView(currentView && currentView !.parent !); leaveView(oldView !);
isParent = _isParent; isParent = _isParent;
previousOrParentNode = _previousOrParentNode; previousOrParentNode = _previousOrParentNode;
} }

View File

@ -119,6 +119,10 @@ describe('ViewContainerRef', () => {
directiveInstance !.insertTpl(); directiveInstance !.insertTpl();
expect(fixture.html).toEqual('before<div testdir=""></div>From a template.after'); expect(fixture.html).toEqual('before<div testdir=""></div>From a template.after');
// run change-detection cycle with no template insertion / removal
fixture.update();
expect(fixture.html).toEqual('before<div testdir=""></div>From a template.after');
directiveInstance !.insertTpl(); directiveInstance !.insertTpl();
expect(fixture.html) expect(fixture.html)
.toEqual('before<div testdir=""></div>From a template.From a template.after'); .toEqual('before<div testdir=""></div>From a template.From a template.after');
@ -178,6 +182,10 @@ describe('ViewContainerRef', () => {
directiveInstance !.insertTpl({name: 'World'}); directiveInstance !.insertTpl({name: 'World'});
expect(fixture.html).toEqual('before|Hello, World|after'); expect(fixture.html).toEqual('before|Hello, World|after');
// run change-detection cycle with no template insertion / removal
fixture.update();
expect(fixture.html).toEqual('before|Hello, World|after');
directiveInstance !.remove(0); directiveInstance !.remove(0);
expect(fixture.html).toEqual('before||after'); expect(fixture.html).toEqual('before||after');
}); });