Skip to content

Commit b576868

Browse files
committed
refactor(portal): rename PortalHost to PortalOutlet
Renames the `PortalHost` and related symbols to `PortalOutlet` for consistency with core. Fixes #7544.
1 parent 0834a31 commit b576868

20 files changed

+135
-125
lines changed

src/cdk/overlay/overlay-ref.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*/
88

99
import {NgZone} from '@angular/core';
10-
import {PortalHost, Portal} from '@angular/cdk/portal';
10+
import {PortalOutlet, Portal} from '@angular/cdk/portal';
1111
import {OverlayConfig} from './overlay-config';
1212
import {Observable} from 'rxjs/Observable';
1313
import {Subject} from 'rxjs/Subject';
@@ -17,14 +17,14 @@ import {Subject} from 'rxjs/Subject';
1717
* Reference to an overlay that has been created with the Overlay service.
1818
* Used to manipulate or dispose of said overlay.
1919
*/
20-
export class OverlayRef implements PortalHost {
20+
export class OverlayRef implements PortalOutlet {
2121
private _backdropElement: HTMLElement | null = null;
2222
private _backdropClick: Subject<any> = new Subject();
2323
private _attachments = new Subject<void>();
2424
private _detachments = new Subject<void>();
2525

2626
constructor(
27-
private _portalHost: PortalHost,
27+
private _portalOutlet: PortalOutlet,
2828
private _pane: HTMLElement,
2929
private _config: OverlayConfig,
3030
private _ngZone: NgZone) {
@@ -45,7 +45,7 @@ export class OverlayRef implements PortalHost {
4545
* @returns The portal attachment result.
4646
*/
4747
attach(portal: Portal<any>): any {
48-
let attachResult = this._portalHost.attach(portal);
48+
let attachResult = this._portalOutlet.attach(portal);
4949

5050
if (this._config.positionStrategy) {
5151
this._config.positionStrategy.attach(this);
@@ -103,7 +103,7 @@ export class OverlayRef implements PortalHost {
103103
this._config.scrollStrategy.disable();
104104
}
105105

106-
const detachmentResult = this._portalHost.detach();
106+
const detachmentResult = this._portalOutlet.detach();
107107

108108
// Only emit after everything is detached.
109109
this._detachments.next();
@@ -124,7 +124,7 @@ export class OverlayRef implements PortalHost {
124124
}
125125

126126
this.detachBackdrop();
127-
this._portalHost.dispose();
127+
this._portalOutlet.dispose();
128128
this._attachments.complete();
129129
this._backdropClick.complete();
130130
this._detachments.next();
@@ -135,7 +135,7 @@ export class OverlayRef implements PortalHost {
135135
* Checks whether the overlay has been attached.
136136
*/
137137
hasAttached(): boolean {
138-
return this._portalHost.hasAttached();
138+
return this._portalOutlet.hasAttached();
139139
}
140140

141141
/**

src/cdk/overlay/overlay.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ The `Overlay` service provides a way to open floating panels on the screen.
66
Calling `overlay.create()` will return an `OverlayRef` instance. This instance is a handle for
77
managing that specific overlay.
88

9-
The `OverlayRef` _is_ a `PortalHost`- once created, content can be added by attaching a `Portal`.
9+
The `OverlayRef` _is_ a `PortalOutlet`- once created, content can be added by attaching a `Portal`.
1010
See the documentation on portals for further information.
1111
```ts
1212
const overlayRef = overlay.create();

src/cdk/overlay/overlay.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import {
1313
Injector,
1414
NgZone,
1515
} from '@angular/core';
16-
import {DomPortalHost} from '@angular/cdk/portal';
16+
import {DomPortalOutlet} from '@angular/cdk/portal';
1717
import {OverlayConfig} from './overlay-config';
1818
import {OverlayRef} from './overlay-ref';
1919
import {OverlayPositionBuilder} from './position/overlay-position-builder';
@@ -34,7 +34,7 @@ let defaultConfig = new OverlayConfig();
3434
* selects, etc. can all be built using overlays. The service should primarily be used by authors
3535
* of re-usable components rather than developers building end-user applications.
3636
*
37-
* An overlay *is* a PortalHost, so any kind of Portal can be loaded into one.
37+
* An overlay *is* a PortalOutlet, so any kind of Portal can be loaded into one.
3838
*/
3939
@Injectable()
4040
export class Overlay {
@@ -53,8 +53,8 @@ export class Overlay {
5353
*/
5454
create(config: OverlayConfig = defaultConfig): OverlayRef {
5555
const pane = this._createPaneElement();
56-
const portalHost = this._createPortalHost(pane);
57-
return new OverlayRef(portalHost, pane, config, this._ngZone);
56+
const portalOutlet = this._createPortalOutlet(pane);
57+
return new OverlayRef(portalOutlet, pane, config, this._ngZone);
5858
}
5959

6060
/**
@@ -80,11 +80,11 @@ export class Overlay {
8080
}
8181

8282
/**
83-
* Create a DomPortalHost into which the overlay content can be loaded.
84-
* @param pane The DOM element to turn into a portal host.
85-
* @returns A portal host for the given DOM element.
83+
* Create a DomPortalOutlet into which the overlay content can be loaded.
84+
* @param pane The DOM element to turn into a portal outlet.
85+
* @returns A portal outlet for the given DOM element.
8686
*/
87-
private _createPortalHost(pane: HTMLElement): DomPortalHost {
88-
return new DomPortalHost(pane, this._componentFactoryResolver, this._appRef, this._injector);
87+
private _createPortalOutlet(pane: HTMLElement): DomPortalOutlet {
88+
return new DomPortalOutlet(pane, this._componentFactoryResolver, this._appRef, this._injector);
8989
}
9090
}

src/cdk/portal/dom-portal-host.ts renamed to src/cdk/portal/dom-portal-outlet.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,16 @@ import {
1313
ApplicationRef,
1414
Injector,
1515
} from '@angular/core';
16-
import {BasePortalHost, ComponentPortal, TemplatePortal} from './portal';
16+
import {BasePortalOutlet, ComponentPortal, TemplatePortal} from './portal';
1717

1818

1919
/**
20-
* A PortalHost for attaching portals to an arbitrary DOM element outside of the Angular
20+
* A PortalOutlet for attaching portals to an arbitrary DOM element outside of the Angular
2121
* application context.
2222
*
2323
* This is the only part of the portal core that directly touches the DOM.
2424
*/
25-
export class DomPortalHost extends BasePortalHost {
25+
export class DomPortalOutlet extends BasePortalOutlet {
2626
constructor(
2727
private _hostDomElement: Element,
2828
private _componentFactoryResolver: ComponentFactoryResolver,
@@ -75,8 +75,9 @@ export class DomPortalHost extends BasePortalHost {
7575
viewRef.detectChanges();
7676

7777
// The method `createEmbeddedView` will add the view as a child of the viewContainer.
78-
// But for the DomPortalHost the view can be added everywhere in the DOM (e.g Overlay Container)
79-
// To move the view to the specified host element. We just re-append the existing root nodes.
78+
// But for the DomPortalOutlet the view can be added everywhere in the DOM
79+
// (e.g Overlay Container) To move the view to the specified host element. We just
80+
// re-append the existing root nodes.
8081
viewRef.rootNodes.forEach(rootNode => this._hostDomElement.appendChild(rootNode));
8182

8283
this.setDisposeFn((() => {

src/cdk/portal/portal-directives.ts

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import {
1717
OnDestroy,
1818
Input,
1919
} from '@angular/core';
20-
import {Portal, TemplatePortal, ComponentPortal, BasePortalHost} from './portal';
20+
import {Portal, TemplatePortal, ComponentPortal, BasePortalOutlet} from './portal';
2121

2222

2323
/**
@@ -41,18 +41,18 @@ export class TemplatePortalDirective extends TemplatePortal<any> {
4141

4242

4343
/**
44-
* Directive version of a PortalHost. Because the directive *is* a PortalHost, portals can be
44+
* Directive version of a PortalOutlet. Because the directive *is* a PortalOutlet, portals can be
4545
* directly attached to it, enabling declarative use.
4646
*
4747
* Usage:
48-
* <ng-template [cdkPortalHost]="greeting"></ng-template>
48+
* <ng-template [cdkPortalOutlet]="greeting"></ng-template>
4949
*/
5050
@Directive({
51-
selector: '[cdkPortalHost], [portalHost]',
52-
exportAs: 'cdkPortalHost',
53-
inputs: ['portal: cdkPortalHost']
51+
selector: '[cdkPortalOutlet], [cdkPortalHost], [portalHost]',
52+
exportAs: 'cdkPortalOutlet, cdkPortalHost',
53+
inputs: ['portal: cdkPortalOutlet']
5454
})
55-
export class PortalHostDirective extends BasePortalHost implements OnDestroy {
55+
export class PortalOutletDirective extends BasePortalOutlet implements OnDestroy {
5656
/** The attached portal. */
5757
private _portal: Portal<any> | null = null;
5858

@@ -67,7 +67,12 @@ export class PortalHostDirective extends BasePortalHost implements OnDestroy {
6767
get _deprecatedPortal() { return this.portal; }
6868
set _deprecatedPortal(v) { this.portal = v; }
6969

70-
/** Portal associated with the Portal host. */
70+
/** @deprecated */
71+
@Input('cdkPortalHost')
72+
get _deprecatedPortalHost() { return this.portal; }
73+
set _deprecatedPortalHost(v) { this.portal = v; }
74+
75+
/** Portal associated with the Portal outlet. */
7176
get portal(): Portal<any> | null {
7277
return this._portal;
7378
}
@@ -90,15 +95,15 @@ export class PortalHostDirective extends BasePortalHost implements OnDestroy {
9095
}
9196

9297
/**
93-
* Attach the given ComponentPortal to this PortalHost using the ComponentFactoryResolver.
98+
* Attach the given ComponentPortal to this PortalOutlet using the ComponentFactoryResolver.
9499
*
95-
* @param portal Portal to be attached to the portal host.
100+
* @param portal Portal to be attached to the portal outlet.
96101
*/
97102
attachComponentPortal<T>(portal: ComponentPortal<T>): ComponentRef<T> {
98103
portal.setAttachedHost(this);
99104

100105
// If the portal specifies an origin, use that as the logical location of the component
101-
// in the application tree. Otherwise use the location of this PortalHost.
106+
// in the application tree. Otherwise use the location of this PortalOutlet.
102107
let viewContainerRef = portal.viewContainerRef != null ?
103108
portal.viewContainerRef :
104109
this._viewContainerRef;
@@ -132,7 +137,7 @@ export class PortalHostDirective extends BasePortalHost implements OnDestroy {
132137

133138

134139
@NgModule({
135-
exports: [TemplatePortalDirective, PortalHostDirective],
136-
declarations: [TemplatePortalDirective, PortalHostDirective],
140+
exports: [TemplatePortalDirective, PortalOutletDirective],
141+
declarations: [TemplatePortalDirective, PortalOutletDirective],
137142
})
138143
export class PortalModule {}

src/cdk/portal/portal-errors.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,25 +26,25 @@ export function throwPortalAlreadyAttachedError() {
2626
* Throws an exception when attempting to attach a portal to an already-disposed host.
2727
* @docs-private
2828
*/
29-
export function throwPortalHostAlreadyDisposedError() {
30-
throw Error('This PortalHost has already been disposed');
29+
export function throwPortalOutletAlreadyDisposedError() {
30+
throw Error('This PortalOutlet has already been disposed');
3131
}
3232

3333
/**
3434
* Throws an exception when attempting to attach an unknown portal type.
3535
* @docs-private
3636
*/
3737
export function throwUnknownPortalTypeError() {
38-
throw Error('Attempting to attach an unknown Portal type. BasePortalHost accepts either ' +
39-
'a ComponentPortal or a TemplatePortal.');
38+
throw Error('Attempting to attach an unknown Portal type. BasePortalOutlet accepts either ' +
39+
'a ComponentPortal or a TemplatePortal.');
4040
}
4141

4242
/**
4343
* Throws an exception when attempting to attach a portal to a null host.
4444
* @docs-private
4545
*/
46-
export function throwNullPortalHostError() {
47-
throw Error('Attempting to attach a portal to a null PortalHost');
46+
export function throwNullPortalOutletError() {
47+
throw Error('Attempting to attach a portal to a null PortalOutlet');
4848
}
4949

5050
/**

src/cdk/portal/portal.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
11
### Portals
22
A `Portal `is a piece of UI that can be dynamically rendered to an open slot on the page.
33

4-
The "piece of UI" can be either a `Component` or a `TemplateRef` and the "open slot" is
5-
a `PortalHost`.
4+
The "piece of UI" can be either a `Component` or a `TemplateRef` and the "open slot" is
5+
a `PortalOutlet`.
66

7-
Portals and PortalHosts are low-level building blocks that other concepts, such as overlays, are
7+
Portals and PortalOutlets are low-level building blocks that other concepts, such as overlays, are
88
built upon.
99

1010
##### `Portal<T>`
1111
| Method | Description |
1212
| --- | --- |
13-
| `attach(PortalHost): Promise<T>` | Attaches the portal to a host. |
13+
| `attach(PortalOutlet): Promise<T>` | Attaches the portal to a host. |
1414
| `detach(): Promise<void>` | Detaches the portal from its host. |
1515
| `isAttached: boolean` | Whether the portal is attached. |
1616

17-
##### `PortalHost`
17+
##### `PortalOutlet`
1818
| Method | Description |
1919
| --- | --- |
2020
| `attach(Portal): Promise<void>` | Attaches a portal to the host. |
@@ -55,11 +55,11 @@ this.userSettingsPortal = new ComponentPortal(UserSettingsComponent);
5555
```
5656

5757

58-
##### `PortalHostDirective`
59-
Used to add a portal host to a template. `PortalHostDirective` *is* a `PortalHost`.
58+
##### `PortalOutletDirective`
59+
Used to add a portal outlet to a template. `PortalOutletDirective` *is* a `PortalOutlet`.
6060

6161
Usage:
6262
```html
6363
<!-- Attaches the `userSettingsPortal` from the previous example. -->
64-
<ng-template [cdkPortalHost]="userSettingsPortal"></ng-template>
64+
<ng-template [cdkPortalOutlet]="userSettingsPortal"></ng-template>
6565
```

0 commit comments

Comments
 (0)