Skip to content

Commit 00de3f6

Browse files
crisbetommalerba
authored andcommitted
refactor(portal): rename PortalHost to PortalOutlet (#7546)
Renames the `PortalHost` and related symbols to `PortalOutlet` for consistency with core. Fixes #7544.
1 parent f601e83 commit 00de3f6

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 {OverlayKeyboardDispatcher} from './keyboard/overlay-keyboard-dispatcher';
1313
import {Observable} from 'rxjs/Observable';
@@ -19,7 +19,7 @@ import {first} from 'rxjs/operators';
1919
* Reference to an overlay that has been created with the Overlay service.
2020
* Used to manipulate or dispose of said overlay.
2121
*/
22-
export class OverlayRef implements PortalHost {
22+
export class OverlayRef implements PortalOutlet {
2323
private _backdropElement: HTMLElement | null = null;
2424
private _backdropClick: Subject<any> = new Subject();
2525
private _attachments = new Subject<void>();
@@ -29,7 +29,7 @@ export class OverlayRef implements PortalHost {
2929
_keydownEvents = new Subject<KeyboardEvent>();
3030

3131
constructor(
32-
private _portalHost: PortalHost,
32+
private _portalOutlet: PortalOutlet,
3333
private _pane: HTMLElement,
3434
private _config: OverlayConfig,
3535
private _ngZone: NgZone,
@@ -51,7 +51,7 @@ export class OverlayRef implements PortalHost {
5151
* @returns The portal attachment result.
5252
*/
5353
attach(portal: Portal<any>): any {
54-
let attachResult = this._portalHost.attach(portal);
54+
let attachResult = this._portalOutlet.attach(portal);
5555

5656
if (this._config.positionStrategy) {
5757
this._config.positionStrategy.attach(this);
@@ -118,7 +118,7 @@ export class OverlayRef implements PortalHost {
118118
this._config.scrollStrategy.disable();
119119
}
120120

121-
const detachmentResult = this._portalHost.detach();
121+
const detachmentResult = this._portalOutlet.detach();
122122

123123
// Only emit after everything is detached.
124124
this._detachments.next();
@@ -142,7 +142,7 @@ export class OverlayRef implements PortalHost {
142142
}
143143

144144
this.detachBackdrop();
145-
this._portalHost.dispose();
145+
this._portalOutlet.dispose();
146146
this._attachments.complete();
147147
this._backdropClick.complete();
148148
this._detachments.next();
@@ -153,7 +153,7 @@ export class OverlayRef implements PortalHost {
153153
* Checks whether the overlay has been attached.
154154
*/
155155
hasAttached(): boolean {
156-
return this._portalHost.hasAttached();
156+
return this._portalOutlet.hasAttached();
157157
}
158158

159159
/**

src/cdk/overlay/overlay.md

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

7-
The `OverlayRef` _is_ a `PortalHost`- once created, content can be added by attaching a `Portal`.
7+
The `OverlayRef` _is_ a `PortalOutlet`- once created, content can be added by attaching a `Portal`.
88
See the documentation on portals for further information.
99
```ts
1010
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';
@@ -35,7 +35,7 @@ let defaultConfig = new OverlayConfig();
3535
* selects, etc. can all be built using overlays. The service should primarily be used by authors
3636
* of re-usable components rather than developers building end-user applications.
3737
*
38-
* An overlay *is* a PortalHost, so any kind of Portal can be loaded into one.
38+
* An overlay *is* a PortalOutlet, so any kind of Portal can be loaded into one.
3939
*/
4040
@Injectable()
4141
export class Overlay {
@@ -57,8 +57,8 @@ export class Overlay {
5757
*/
5858
create(config: OverlayConfig = defaultConfig): OverlayRef {
5959
const pane = this._createPaneElement();
60-
const portalHost = this._createPortalHost(pane);
61-
return new OverlayRef(portalHost, pane, config, this._ngZone, this._keyboardDispatcher);
60+
const portalOutlet = this._createPortalOutlet(pane);
61+
return new OverlayRef(portalOutlet, pane, config, this._ngZone, this._keyboardDispatcher);
6262
}
6363

6464
/**
@@ -85,12 +85,12 @@ export class Overlay {
8585
}
8686

8787
/**
88-
* Create a DomPortalHost into which the overlay content can be loaded.
89-
* @param pane The DOM element to turn into a portal host.
90-
* @returns A portal host for the given DOM element.
88+
* Create a DomPortalOutlet into which the overlay content can be loaded.
89+
* @param pane The DOM element to turn into a portal outlet.
90+
* @returns A portal outlet for the given DOM element.
9191
*/
92-
private _createPortalHost(pane: HTMLElement): DomPortalHost {
93-
return new DomPortalHost(pane, this._componentFactoryResolver, this._appRef, this._injector);
92+
private _createPortalOutlet(pane: HTMLElement): DomPortalOutlet {
93+
return new DomPortalOutlet(pane, this._componentFactoryResolver, this._appRef, this._injector);
9494
}
9595

9696
}

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,14 +13,14 @@ 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
*/
23-
export class DomPortalHost extends BasePortalHost {
23+
export class DomPortalOutlet extends BasePortalOutlet {
2424
constructor(
2525
private _hostDomElement: Element,
2626
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
/**
@@ -36,18 +36,18 @@ export class TemplatePortalDirective extends TemplatePortal<any> {
3636

3737

3838
/**
39-
* Directive version of a PortalHost. Because the directive *is* a PortalHost, portals can be
39+
* Directive version of a PortalOutlet. Because the directive *is* a PortalOutlet, portals can be
4040
* directly attached to it, enabling declarative use.
4141
*
4242
* Usage:
43-
* <ng-template [cdkPortalHost]="greeting"></ng-template>
43+
* <ng-template [cdkPortalOutlet]="greeting"></ng-template>
4444
*/
4545
@Directive({
46-
selector: '[cdkPortalHost], [portalHost]',
47-
exportAs: 'cdkPortalHost',
48-
inputs: ['portal: cdkPortalHost']
46+
selector: '[cdkPortalOutlet], [cdkPortalHost], [portalHost]',
47+
exportAs: 'cdkPortalOutlet, cdkPortalHost',
48+
inputs: ['portal: cdkPortalOutlet']
4949
})
50-
export class PortalHostDirective extends BasePortalHost implements OnDestroy {
50+
export class PortalOutletDirective extends BasePortalOutlet implements OnDestroy {
5151
/** The attached portal. */
5252
private _portal: Portal<any> | null = null;
5353

@@ -62,7 +62,12 @@ export class PortalHostDirective extends BasePortalHost implements OnDestroy {
6262
get _deprecatedPortal() { return this.portal; }
6363
set _deprecatedPortal(v) { this.portal = v; }
6464

65-
/** Portal associated with the Portal host. */
65+
/** @deprecated */
66+
@Input('cdkPortalHost')
67+
get _deprecatedPortalHost() { return this.portal; }
68+
set _deprecatedPortalHost(v) { this.portal = v; }
69+
70+
/** Portal associated with the Portal outlet. */
6671
get portal(): Portal<any> | null {
6772
return this._portal;
6873
}
@@ -85,16 +90,16 @@ export class PortalHostDirective extends BasePortalHost implements OnDestroy {
8590
}
8691

8792
/**
88-
* Attach the given ComponentPortal to this PortalHost using the ComponentFactoryResolver.
93+
* Attach the given ComponentPortal to this PortalOutlet using the ComponentFactoryResolver.
8994
*
90-
* @param portal Portal to be attached to the portal host.
95+
* @param portal Portal to be attached to the portal outlet.
9196
* @returns Reference to the created component.
9297
*/
9398
attachComponentPortal<T>(portal: ComponentPortal<T>): ComponentRef<T> {
9499
portal.setAttachedHost(this);
95100

96101
// If the portal specifies an origin, use that as the logical location of the component
97-
// in the application tree. Otherwise use the location of this PortalHost.
102+
// in the application tree. Otherwise use the location of this PortalOutlet.
98103
let viewContainerRef = portal.viewContainerRef != null ?
99104
portal.viewContainerRef :
100105
this._viewContainerRef;
@@ -129,7 +134,7 @@ export class PortalHostDirective extends BasePortalHost implements OnDestroy {
129134

130135

131136
@NgModule({
132-
exports: [TemplatePortalDirective, PortalHostDirective],
133-
declarations: [TemplatePortalDirective, PortalHostDirective],
137+
exports: [TemplatePortalDirective, PortalOutletDirective],
138+
declarations: [TemplatePortalDirective, PortalOutletDirective],
134139
})
135140
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
@@ -3,20 +3,20 @@ The `portals` package provides a flexible system for rendering dynamic content i
33
### Portals
44
A `Portal `is a piece of UI that can be dynamically rendered to an open slot on the page.
55

6-
The "piece of UI" can be either a `Component` or a `TemplateRef` and the "open slot" is
7-
a `PortalHost`.
6+
The "piece of UI" can be either a `Component` or a `TemplateRef` and the "open slot" is
7+
a `PortalOutlet`.
88

9-
Portals and PortalHosts are low-level building blocks that other concepts, such as overlays, are
9+
Portals and PortalOutlets are low-level building blocks that other concepts, such as overlays, are
1010
built upon.
1111

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

19-
##### `PortalHost`
19+
##### `PortalOutlet`
2020
| Method | Description |
2121
| --- | --- |
2222
| `attach(Portal): Promise<void>` | Attaches a portal to the host. |
@@ -57,11 +57,11 @@ this.userSettingsPortal = new ComponentPortal(UserSettingsComponent);
5757
```
5858

5959

60-
##### `PortalHostDirective`
61-
Used to add a portal host to a template. `PortalHostDirective` *is* a `PortalHost`.
60+
##### `PortalOutletDirective`
61+
Used to add a portal outlet to a template. `PortalOutletDirective` *is* a `PortalOutlet`.
6262

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

0 commit comments

Comments
 (0)