Skip to content

Commit dd1f0fc

Browse files
jelbournandrewseguin
authored andcommitted
chore(portal): remove obsolete code for Angular < 2.3 (#2791)
1 parent 2bd607c commit dd1f0fc

File tree

1 file changed

+6
-34
lines changed

1 file changed

+6
-34
lines changed

src/lib/core/portal/dom-portal-host.ts

Lines changed: 6 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,7 @@ export class DomPortalHost extends BasePortalHost {
3434
// If the portal specifies a ViewContainerRef, we will use that as the attachment point
3535
// for the component (in terms of Angular's component tree, not rendering).
3636
// When the ViewContainerRef is missing, we use the factory to create the component directly
37-
// and then manually attach the ChangeDetector for that component to the application (which
38-
// happens automatically when using a ViewContainer).
37+
// and then manually attach the view to the application.
3938
if (portal.viewContainerRef) {
4039
componentRef = portal.viewContainerRef.createComponent(
4140
componentFactory,
@@ -45,39 +44,12 @@ export class DomPortalHost extends BasePortalHost {
4544
this.setDisposeFn(() => componentRef.destroy());
4645
} else {
4746
componentRef = componentFactory.create(portal.injector || this._defaultInjector);
48-
49-
// ApplicationRef's attachView and detachView methods are in Angular ^2.3.0 but not before.
50-
// The `else` clause here can be removed once 2.3.0 is released.
51-
if ((this._appRef as any)['attachView']) {
52-
(this._appRef as any).attachView(componentRef.hostView);
53-
54-
this.setDisposeFn(() => {
55-
(this._appRef as any).detachView(componentRef.hostView);
56-
componentRef.destroy();
57-
});
58-
} else {
59-
// When creating a component outside of a ViewContainer, we need to manually register
60-
// its ChangeDetector with the application. This API is unfortunately not published
61-
// in Angular < 2.3.0. The change detector must also be deregistered when the component
62-
// is destroyed to prevent memory leaks.
63-
let changeDetectorRef = componentRef.changeDetectorRef;
64-
(this._appRef as any).registerChangeDetector(changeDetectorRef);
65-
66-
this.setDisposeFn(() => {
67-
(this._appRef as any).unregisterChangeDetector(changeDetectorRef);
68-
69-
// Normally the ViewContainer will remove the component's nodes from the DOM.
70-
// Without a ViewContainer, we need to manually remove the nodes.
71-
let componentRootNode = this._getComponentRootNode(componentRef);
72-
if (componentRootNode.parentNode) {
73-
componentRootNode.parentNode.removeChild(componentRootNode);
74-
}
75-
76-
componentRef.destroy();
77-
});
78-
}
47+
this._appRef.attachView(componentRef.hostView);
48+
this.setDisposeFn(() => {
49+
this._appRef.detachView(componentRef.hostView);
50+
componentRef.destroy();
51+
});
7952
}
80-
8153
// At this point the component has been instantiated, so we move it to the location in the DOM
8254
// where we want it to be rendered.
8355
this._hostDomElement.appendChild(this._getComponentRootNode(componentRef));

0 commit comments

Comments
 (0)