fix(ivy): ngTemplateOutlet error when switching between null and template value (#32160)
Fixes an error that is thrown by `ngTemplateOutlet` under Ivy when switching from a template to null and back to a template. The error is thrown because the reference to the previous ViewRef is never cleared and the directive tries to detach a view that has already been detached. Fixes #32060. PR Close #32160
This commit is contained in:

committed by
Andrew Kushnir

parent
994264c0ba
commit
c2868de25a
@ -55,18 +55,17 @@ export class NgTemplateOutlet implements OnChanges {
|
||||
const recreateView = this._shouldRecreateView(changes);
|
||||
|
||||
if (recreateView) {
|
||||
const viewContainerRef = this._viewContainerRef;
|
||||
|
||||
if (this._viewRef) {
|
||||
this._viewContainerRef.remove(this._viewContainerRef.indexOf(this._viewRef));
|
||||
viewContainerRef.remove(viewContainerRef.indexOf(this._viewRef));
|
||||
}
|
||||
|
||||
if (this.ngTemplateOutlet) {
|
||||
this._viewRef = this._viewContainerRef.createEmbeddedView(
|
||||
this.ngTemplateOutlet, this.ngTemplateOutletContext);
|
||||
}
|
||||
} else {
|
||||
if (this._viewRef && this.ngTemplateOutletContext) {
|
||||
this._updateExistingContext(this.ngTemplateOutletContext);
|
||||
}
|
||||
this._viewRef = this.ngTemplateOutlet ?
|
||||
viewContainerRef.createEmbeddedView(this.ngTemplateOutlet, this.ngTemplateOutletContext) :
|
||||
null;
|
||||
} else if (this._viewRef && this.ngTemplateOutletContext) {
|
||||
this._updateExistingContext(this.ngTemplateOutletContext);
|
||||
}
|
||||
}
|
||||
|
||||
@ -96,9 +95,8 @@ export class NgTemplateOutlet implements OnChanges {
|
||||
}
|
||||
}
|
||||
return false;
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private _updateExistingContext(ctx: Object): void {
|
||||
|
Reference in New Issue
Block a user