Skip to content

Commit f242091

Browse files
committed
remove template portal
1 parent 3741f33 commit f242091

File tree

3 files changed

+11
-46
lines changed

3 files changed

+11
-46
lines changed

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

+1-18
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import {
55
ApplicationRef,
66
Injector,
77
} from '@angular/core';
8-
import {BasePortalHost, ComponentPortal, TemplatePortal} from './portal';
8+
import {BasePortalHost, ComponentPortal} from './portal';
99

1010

1111
/**
@@ -64,23 +64,6 @@ export class DomPortalHost extends BasePortalHost {
6464
return componentRef;
6565
}
6666

67-
attachTemplatePortal(portal: TemplatePortal): Map<string, any> {
68-
let viewContainer = portal.viewContainerRef;
69-
let viewRef = viewContainer.createEmbeddedView(portal.templateRef);
70-
71-
viewRef.rootNodes.forEach(rootNode => this._hostDomElement.appendChild(rootNode));
72-
73-
this.setDisposeFn((() => {
74-
let index = viewContainer.indexOf(viewRef);
75-
if (index !== -1) {
76-
viewContainer.remove(index);
77-
}
78-
}));
79-
80-
// TODO(jelbourn): Return locals from view.
81-
return new Map<string, any>();
82-
}
83-
8467
dispose(): void {
8568
super.dispose();
8669
if (this._hostDomElement.parentNode !== null) {

src/lib/portal/portal-errors.ts

-9
Original file line numberDiff line numberDiff line change
@@ -30,15 +30,6 @@ export class MdPortalHostAlreadyDisposedError extends MdError {
3030
}
3131
}
3232

33-
/** Exception thrown when attempting to attach an unknown portal type. */
34-
export class MdUnknownPortalTypeError extends MdError {
35-
constructor() {
36-
super(
37-
'Attempting to attach an unknown Portal type. ' +
38-
'BasePortalHost accepts either a ComponentPortal or a TemplatePortal.');
39-
}
40-
}
41-
4233
/** Exception thrown when attempting to attach a portal to a null host. */
4334
export class MdNullPortalHostError extends MdError {
4435
constructor() {

src/lib/portal/portal.ts

+10-19
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import {
1111
MdNoPortalAttachedError,
1212
MdNullPortalError,
1313
MdPortalHostAlreadyDisposedError,
14-
MdUnknownPortalTypeError
1514
} from './portal-errors';
1615
import { ComponentType } from '../overlay/generic-component-type';
1716

@@ -149,7 +148,7 @@ export interface PortalHost {
149148

150149
/**
151150
* Partial implementation of PortalHost that only deals with attaching either a
152-
* ComponentPortal or a TemplatePortal.
151+
* ComponentPortal
153152
*/
154153
export abstract class BasePortalHost implements PortalHost {
155154
/** The portal currently attached to the host. */
@@ -163,10 +162,10 @@ export abstract class BasePortalHost implements PortalHost {
163162

164163
/** Whether this host has an attached portal. */
165164
hasAttached() {
166-
return this._attachedPortal != null;
165+
return this._attachedPortal !== undefined;
167166
}
168167

169-
attach(portal: Portal<any>, newestOnTop: boolean): any {
168+
attach(portal: ComponentPortal<any>, newestOnTop: boolean): any {
170169
if (portal == null) {
171170
throw new MdNullPortalError();
172171
}
@@ -178,28 +177,20 @@ export abstract class BasePortalHost implements PortalHost {
178177
if (this._isDisposed) {
179178
throw new MdPortalHostAlreadyDisposedError();
180179
}
181-
182-
if (portal instanceof ComponentPortal) {
183-
this._attachedPortal = portal;
184-
return this.attachComponentPortal(portal, newestOnTop);
185-
} else if (portal instanceof TemplatePortal) {
186-
this._attachedPortal = portal;
187-
return this.attachTemplatePortal(portal);
188-
}
189-
190-
throw new MdUnknownPortalTypeError();
180+
this._attachedPortal = portal;
181+
return this.attachComponentPortal(portal, newestOnTop);
191182
}
192183

193-
abstract attachComponentPortal<T>(portal: ComponentPortal<T>,
194-
newestOnTop: boolean): ComponentRef<T>;
195-
196-
abstract attachTemplatePortal(portal: TemplatePortal): Map<string, any>;
184+
abstract attachComponentPortal<T>(
185+
portal: ComponentPortal<T>,
186+
newestOnTop: boolean
187+
): ComponentRef<T>;
197188

198189
detach(): void {
199190
if (this._attachedPortal) { this._attachedPortal.setAttachedHost(null); }
200191

201192
this._attachedPortal = null;
202-
if (this._disposeFn != null) {
193+
if (this._disposeFn) {
203194
this._disposeFn();
204195
this._disposeFn = null;
205196
}

0 commit comments

Comments
 (0)