diff --git a/src/cdk/overlay/overlay-ref.ts b/src/cdk/overlay/overlay-ref.ts index 71684e924bf5..6d35a35f67ff 100644 --- a/src/cdk/overlay/overlay-ref.ts +++ b/src/cdk/overlay/overlay-ref.ts @@ -7,7 +7,7 @@ */ import {NgZone} from '@angular/core'; -import {PortalHost, Portal} from '@angular/cdk/portal'; +import {PortalOutlet, Portal} from '@angular/cdk/portal'; import {OverlayConfig} from './overlay-config'; import {Observable} from 'rxjs/Observable'; import {Subject} from 'rxjs/Subject'; @@ -17,14 +17,14 @@ import {Subject} from 'rxjs/Subject'; * Reference to an overlay that has been created with the Overlay service. * Used to manipulate or dispose of said overlay. */ -export class OverlayRef implements PortalHost { +export class OverlayRef implements PortalOutlet { private _backdropElement: HTMLElement | null = null; private _backdropClick: Subject = new Subject(); private _attachments = new Subject(); private _detachments = new Subject(); constructor( - private _portalHost: PortalHost, + private _portalOutlet: PortalOutlet, private _pane: HTMLElement, private _config: OverlayConfig, private _ngZone: NgZone) { @@ -45,7 +45,7 @@ export class OverlayRef implements PortalHost { * @returns The portal attachment result. */ attach(portal: Portal): any { - let attachResult = this._portalHost.attach(portal); + let attachResult = this._portalOutlet.attach(portal); if (this._config.positionStrategy) { this._config.positionStrategy.attach(this); @@ -103,7 +103,7 @@ export class OverlayRef implements PortalHost { this._config.scrollStrategy.disable(); } - const detachmentResult = this._portalHost.detach(); + const detachmentResult = this._portalOutlet.detach(); // Only emit after everything is detached. this._detachments.next(); @@ -124,7 +124,7 @@ export class OverlayRef implements PortalHost { } this.detachBackdrop(); - this._portalHost.dispose(); + this._portalOutlet.dispose(); this._attachments.complete(); this._backdropClick.complete(); this._detachments.next(); @@ -135,7 +135,7 @@ export class OverlayRef implements PortalHost { * Checks whether the overlay has been attached. */ hasAttached(): boolean { - return this._portalHost.hasAttached(); + return this._portalOutlet.hasAttached(); } /** diff --git a/src/cdk/overlay/overlay.md b/src/cdk/overlay/overlay.md index f37cce43fe7a..320105d6983d 100644 --- a/src/cdk/overlay/overlay.md +++ b/src/cdk/overlay/overlay.md @@ -6,7 +6,7 @@ The `Overlay` service provides a way to open floating panels on the screen. Calling `overlay.create()` will return an `OverlayRef` instance. This instance is a handle for managing that specific overlay. -The `OverlayRef` _is_ a `PortalHost`- once created, content can be added by attaching a `Portal`. +The `OverlayRef` _is_ a `PortalOutlet`- once created, content can be added by attaching a `Portal`. See the documentation on portals for further information. ```ts const overlayRef = overlay.create(); diff --git a/src/cdk/overlay/overlay.ts b/src/cdk/overlay/overlay.ts index 2bfa74a58126..695f77101379 100644 --- a/src/cdk/overlay/overlay.ts +++ b/src/cdk/overlay/overlay.ts @@ -13,7 +13,7 @@ import { Injector, NgZone, } from '@angular/core'; -import {DomPortalHost} from '@angular/cdk/portal'; +import {DomPortalOutlet} from '@angular/cdk/portal'; import {OverlayConfig} from './overlay-config'; import {OverlayRef} from './overlay-ref'; import {OverlayPositionBuilder} from './position/overlay-position-builder'; @@ -34,7 +34,7 @@ let defaultConfig = new OverlayConfig(); * selects, etc. can all be built using overlays. The service should primarily be used by authors * of re-usable components rather than developers building end-user applications. * - * An overlay *is* a PortalHost, so any kind of Portal can be loaded into one. + * An overlay *is* a PortalOutlet, so any kind of Portal can be loaded into one. */ @Injectable() export class Overlay { @@ -53,8 +53,8 @@ export class Overlay { */ create(config: OverlayConfig = defaultConfig): OverlayRef { const pane = this._createPaneElement(); - const portalHost = this._createPortalHost(pane); - return new OverlayRef(portalHost, pane, config, this._ngZone); + const portalOutlet = this._createPortalOutlet(pane); + return new OverlayRef(portalOutlet, pane, config, this._ngZone); } /** @@ -80,11 +80,11 @@ export class Overlay { } /** - * Create a DomPortalHost into which the overlay content can be loaded. - * @param pane The DOM element to turn into a portal host. - * @returns A portal host for the given DOM element. + * Create a DomPortalOutlet into which the overlay content can be loaded. + * @param pane The DOM element to turn into a portal outlet. + * @returns A portal outlet for the given DOM element. */ - private _createPortalHost(pane: HTMLElement): DomPortalHost { - return new DomPortalHost(pane, this._componentFactoryResolver, this._appRef, this._injector); + private _createPortalOutlet(pane: HTMLElement): DomPortalOutlet { + return new DomPortalOutlet(pane, this._componentFactoryResolver, this._appRef, this._injector); } } diff --git a/src/cdk/portal/dom-portal-host.ts b/src/cdk/portal/dom-portal-outlet.ts similarity index 88% rename from src/cdk/portal/dom-portal-host.ts rename to src/cdk/portal/dom-portal-outlet.ts index f39b09d7b824..dbd7e53a87c2 100644 --- a/src/cdk/portal/dom-portal-host.ts +++ b/src/cdk/portal/dom-portal-outlet.ts @@ -13,16 +13,16 @@ import { ApplicationRef, Injector, } from '@angular/core'; -import {BasePortalHost, ComponentPortal, TemplatePortal} from './portal'; +import {BasePortalOutlet, ComponentPortal, TemplatePortal} from './portal'; /** - * A PortalHost for attaching portals to an arbitrary DOM element outside of the Angular + * A PortalOutlet for attaching portals to an arbitrary DOM element outside of the Angular * application context. * * This is the only part of the portal core that directly touches the DOM. */ -export class DomPortalHost extends BasePortalHost { +export class DomPortalOutlet extends BasePortalOutlet { constructor( private _hostDomElement: Element, private _componentFactoryResolver: ComponentFactoryResolver, @@ -75,8 +75,9 @@ export class DomPortalHost extends BasePortalHost { viewRef.detectChanges(); // The method `createEmbeddedView` will add the view as a child of the viewContainer. - // But for the DomPortalHost the view can be added everywhere in the DOM (e.g Overlay Container) - // To move the view to the specified host element. We just re-append the existing root nodes. + // But for the DomPortalOutlet the view can be added everywhere in the DOM + // (e.g Overlay Container) To move the view to the specified host element. We just + // re-append the existing root nodes. viewRef.rootNodes.forEach(rootNode => this._hostDomElement.appendChild(rootNode)); this.setDisposeFn((() => { diff --git a/src/cdk/portal/portal-directives.ts b/src/cdk/portal/portal-directives.ts index 9f4b9e217067..d2abb047088a 100644 --- a/src/cdk/portal/portal-directives.ts +++ b/src/cdk/portal/portal-directives.ts @@ -17,7 +17,7 @@ import { OnDestroy, Input, } from '@angular/core'; -import {Portal, TemplatePortal, ComponentPortal, BasePortalHost} from './portal'; +import {Portal, TemplatePortal, ComponentPortal, BasePortalOutlet} from './portal'; /** @@ -41,18 +41,18 @@ export class TemplatePortalDirective extends TemplatePortal { /** - * Directive version of a PortalHost. Because the directive *is* a PortalHost, portals can be + * Directive version of a PortalOutlet. Because the directive *is* a PortalOutlet, portals can be * directly attached to it, enabling declarative use. * * Usage: - * + * */ @Directive({ - selector: '[cdkPortalHost], [portalHost]', - exportAs: 'cdkPortalHost', - inputs: ['portal: cdkPortalHost'] + selector: '[cdkPortalOutlet], [cdkPortalHost], [portalHost]', + exportAs: 'cdkPortalOutlet, cdkPortalHost', + inputs: ['portal: cdkPortalOutlet'] }) -export class PortalHostDirective extends BasePortalHost implements OnDestroy { +export class PortalOutletDirective extends BasePortalOutlet implements OnDestroy { /** The attached portal. */ private _portal: Portal | null = null; @@ -67,7 +67,12 @@ export class PortalHostDirective extends BasePortalHost implements OnDestroy { get _deprecatedPortal() { return this.portal; } set _deprecatedPortal(v) { this.portal = v; } - /** Portal associated with the Portal host. */ + /** @deprecated */ + @Input('cdkPortalHost') + get _deprecatedPortalHost() { return this.portal; } + set _deprecatedPortalHost(v) { this.portal = v; } + + /** Portal associated with the Portal outlet. */ get portal(): Portal | null { return this._portal; } @@ -90,15 +95,15 @@ export class PortalHostDirective extends BasePortalHost implements OnDestroy { } /** - * Attach the given ComponentPortal to this PortalHost using the ComponentFactoryResolver. + * Attach the given ComponentPortal to this PortalOutlet using the ComponentFactoryResolver. * - * @param portal Portal to be attached to the portal host. + * @param portal Portal to be attached to the portal outlet. */ attachComponentPortal(portal: ComponentPortal): ComponentRef { portal.setAttachedHost(this); // If the portal specifies an origin, use that as the logical location of the component - // in the application tree. Otherwise use the location of this PortalHost. + // in the application tree. Otherwise use the location of this PortalOutlet. let viewContainerRef = portal.viewContainerRef != null ? portal.viewContainerRef : this._viewContainerRef; @@ -132,7 +137,7 @@ export class PortalHostDirective extends BasePortalHost implements OnDestroy { @NgModule({ - exports: [TemplatePortalDirective, PortalHostDirective], - declarations: [TemplatePortalDirective, PortalHostDirective], + exports: [TemplatePortalDirective, PortalOutletDirective], + declarations: [TemplatePortalDirective, PortalOutletDirective], }) export class PortalModule {} diff --git a/src/cdk/portal/portal-errors.ts b/src/cdk/portal/portal-errors.ts index aa9063e05f5b..45d0c06b95e3 100644 --- a/src/cdk/portal/portal-errors.ts +++ b/src/cdk/portal/portal-errors.ts @@ -26,8 +26,8 @@ export function throwPortalAlreadyAttachedError() { * Throws an exception when attempting to attach a portal to an already-disposed host. * @docs-private */ -export function throwPortalHostAlreadyDisposedError() { - throw Error('This PortalHost has already been disposed'); +export function throwPortalOutletAlreadyDisposedError() { + throw Error('This PortalOutlet has already been disposed'); } /** @@ -35,16 +35,16 @@ export function throwPortalHostAlreadyDisposedError() { * @docs-private */ export function throwUnknownPortalTypeError() { - throw Error('Attempting to attach an unknown Portal type. BasePortalHost accepts either ' + - 'a ComponentPortal or a TemplatePortal.'); + throw Error('Attempting to attach an unknown Portal type. BasePortalOutlet accepts either ' + + 'a ComponentPortal or a TemplatePortal.'); } /** * Throws an exception when attempting to attach a portal to a null host. * @docs-private */ -export function throwNullPortalHostError() { - throw Error('Attempting to attach a portal to a null PortalHost'); +export function throwNullPortalOutletError() { + throw Error('Attempting to attach a portal to a null PortalOutlet'); } /** diff --git a/src/cdk/portal/portal.md b/src/cdk/portal/portal.md index 79910d6c3371..e776a6525eb3 100644 --- a/src/cdk/portal/portal.md +++ b/src/cdk/portal/portal.md @@ -1,20 +1,20 @@ ### Portals A `Portal `is a piece of UI that can be dynamically rendered to an open slot on the page. -The "piece of UI" can be either a `Component` or a `TemplateRef` and the "open slot" is -a `PortalHost`. +The "piece of UI" can be either a `Component` or a `TemplateRef` and the "open slot" is +a `PortalOutlet`. -Portals and PortalHosts are low-level building blocks that other concepts, such as overlays, are +Portals and PortalOutlets are low-level building blocks that other concepts, such as overlays, are built upon. ##### `Portal` | Method | Description | | --- | --- | -| `attach(PortalHost): Promise` | Attaches the portal to a host. | +| `attach(PortalOutlet): Promise` | Attaches the portal to a host. | | `detach(): Promise` | Detaches the portal from its host. | | `isAttached: boolean` | Whether the portal is attached. | -##### `PortalHost` +##### `PortalOutlet` | Method | Description | | --- | --- | | `attach(Portal): Promise` | Attaches a portal to the host. | @@ -55,11 +55,11 @@ this.userSettingsPortal = new ComponentPortal(UserSettingsComponent); ``` -##### `PortalHostDirective` -Used to add a portal host to a template. `PortalHostDirective` *is* a `PortalHost`. +##### `PortalOutletDirective` +Used to add a portal outlet to a template. `PortalOutletDirective` *is* a `PortalOutlet`. Usage: ```html - + ``` diff --git a/src/cdk/portal/portal.spec.ts b/src/cdk/portal/portal.spec.ts index 61496f5ba45c..12afa9028bda 100644 --- a/src/cdk/portal/portal.spec.ts +++ b/src/cdk/portal/portal.spec.ts @@ -13,9 +13,9 @@ import { TemplateRef } from '@angular/core'; import {CommonModule} from '@angular/common'; -import {TemplatePortalDirective, PortalHostDirective, PortalModule} from './portal-directives'; +import {TemplatePortalDirective, PortalOutletDirective, PortalModule} from './portal-directives'; import {Portal, ComponentPortal, TemplatePortal} from './portal'; -import {DomPortalHost} from './dom-portal-host'; +import {DomPortalOutlet} from './dom-portal-outlet'; describe('Portals', () => { @@ -28,7 +28,7 @@ describe('Portals', () => { TestBed.compileComponents(); })); - describe('PortalHostDirective', () => { + describe('PortalOutletDirective', () => { let fixture: ComponentFixture; beforeEach(() => { @@ -71,7 +71,7 @@ describe('Portals', () => { // using TemplatePortal.attach method to set context testAppComponent.selectedPortal = undefined; fixture.detectChanges(); - templatePortal.attach(testAppComponent.portalHost, {$implicit: {status: 'rotten'}}); + templatePortal.attach(testAppComponent.portalOutlet, {$implicit: {status: 'rotten'}}); fixture.detectChanges(); // Expect that the content of the attached portal is present and context given via the // attach method is projected @@ -90,7 +90,7 @@ describe('Portals', () => { // context, the latter should take precedence: testAppComponent.selectedPortal = undefined; fixture.detectChanges(); - templatePortal.attach(testAppComponent.portalHost, {$implicit: {status: 'rotten'}}); + templatePortal.attach(testAppComponent.portalOutlet, {$implicit: {status: 'rotten'}}); fixture.detectChanges(); // Expect that the content of the attached portal is present and and context given via the // attach method is projected and get precedence over constructor context @@ -223,32 +223,32 @@ describe('Portals', () => { testAppComponent.selectedPortal = new ComponentPortal(PizzaMsg); fixture.detectChanges(); - expect(testAppComponent.portalHost.hasAttached()).toBe(true); - expect(testAppComponent.portalHost.portal).toBe(testAppComponent.selectedPortal); + expect(testAppComponent.portalOutlet.hasAttached()).toBe(true); + expect(testAppComponent.portalOutlet.portal).toBe(testAppComponent.selectedPortal); testAppComponent.selectedPortal = null; fixture.detectChanges(); - expect(testAppComponent.portalHost.hasAttached()).toBe(false); - expect(testAppComponent.portalHost.portal).toBeNull(); + expect(testAppComponent.portalOutlet.hasAttached()).toBe(false); + expect(testAppComponent.portalOutlet.portal).toBeNull(); }); it('should set the `portal` when attaching a component portal programmatically', () => { let testAppComponent = fixture.debugElement.componentInstance; let portal = new ComponentPortal(PizzaMsg); - testAppComponent.portalHost.attachComponentPortal(portal); + testAppComponent.portalOutlet.attachComponentPortal(portal); - expect(testAppComponent.portalHost.portal).toBe(portal); + expect(testAppComponent.portalOutlet.portal).toBe(portal); }); it('should set the `portal` when attaching a template portal programmatically', () => { let testAppComponent = fixture.debugElement.componentInstance; fixture.detectChanges(); - testAppComponent.portalHost.attachTemplatePortal(testAppComponent.cakePortal); + testAppComponent.portalOutlet.attachTemplatePortal(testAppComponent.cakePortal); - expect(testAppComponent.portalHost.portal).toBe(testAppComponent.cakePortal); + expect(testAppComponent.portalOutlet.portal).toBe(testAppComponent.cakePortal); }); it('should clear the portal reference on destroy', () => { @@ -257,21 +257,21 @@ describe('Portals', () => { testAppComponent.selectedPortal = new ComponentPortal(PizzaMsg); fixture.detectChanges(); - expect(testAppComponent.portalHost.portal).toBeTruthy(); + expect(testAppComponent.portalOutlet.portal).toBeTruthy(); fixture.destroy(); - expect(testAppComponent.portalHost.portal).toBeNull(); + expect(testAppComponent.portalOutlet.portal).toBeNull(); }); }); - describe('DomPortalHost', () => { + describe('DomPortalOutlet', () => { let componentFactoryResolver: ComponentFactoryResolver; let someViewContainerRef: ViewContainerRef; let someInjector: Injector; let someFixture: ComponentFixture; let someDomElement: HTMLElement; - let host: DomPortalHost; + let host: DomPortalOutlet; let injector: Injector; let appRef: ApplicationRef; @@ -284,7 +284,7 @@ describe('Portals', () => { beforeEach(() => { someDomElement = document.createElement('div'); - host = new DomPortalHost(someDomElement, componentFactoryResolver, appRef, injector); + host = new DomPortalOutlet(someDomElement, componentFactoryResolver, appRef, injector); someFixture = TestBed.createComponent(ArbitraryViewContainerRefComponent); someViewContainerRef = someFixture.componentInstance.viewContainerRef; @@ -397,17 +397,17 @@ describe('Portals', () => { expect(componentInstance instanceof PizzaMsg) .toBe(true, 'Expected a PizzaMsg component to be created'); expect(someDomElement.textContent) - .toContain('Pizza', 'Expected the static string "Pizza" in the DomPortalHost.'); + .toContain('Pizza', 'Expected the static string "Pizza" in the DomPortalOutlet.'); componentInstance.snack = new Chocolate(); someFixture.detectChanges(); expect(someDomElement.textContent) - .toContain('Chocolate', 'Expected the bound string "Chocolate" in the DomPortalHost'); + .toContain('Chocolate', 'Expected the bound string "Chocolate" in the DomPortalOutlet'); host.detach(); expect(someDomElement.innerHTML) - .toBe('', 'Expected the DomPortalHost to be empty after detach'); + .toBe('', 'Expected the DomPortalOutlet to be empty after detach'); }); it('should call the dispose function even if the host has no attached content', () => { @@ -457,12 +457,12 @@ class ArbitraryViewContainerRefComponent { } -/** Test-bed component that contains a portal host and a couple of template portals. */ +/** Test-bed component that contains a portal outlet and a couple of template portals. */ @Component({ selector: 'portal-test', template: `
- +
Cake @@ -481,7 +481,7 @@ class ArbitraryViewContainerRefComponent { }) class PortalTestApp { @ViewChildren(TemplatePortalDirective) portals: QueryList; - @ViewChild(PortalHostDirective) portalHost: PortalHostDirective; + @ViewChild(PortalOutletDirective) portalOutlet: PortalOutletDirective; @ViewChild('templateRef', { read: TemplateRef }) templateRef: TemplateRef; selectedPortal: Portal; diff --git a/src/cdk/portal/portal.ts b/src/cdk/portal/portal.ts index 8352e5b31586..b1d84aab4f83 100644 --- a/src/cdk/portal/portal.ts +++ b/src/cdk/portal/portal.ts @@ -15,11 +15,11 @@ import { Injector } from '@angular/core'; import { - throwNullPortalHostError, + throwNullPortalOutletError, throwPortalAlreadyAttachedError, throwNoPortalAttachedError, throwNullPortalError, - throwPortalHostAlreadyDisposedError, + throwPortalOutletAlreadyDisposedError, throwUnknownPortalTypeError } from './portal-errors'; @@ -30,15 +30,15 @@ export interface ComponentType { /** * A `Portal` is something that you want to render somewhere else. - * It can be attach to / detached from a `PortalHost`. + * It can be attach to / detached from a `PortalOutlet`. */ export abstract class Portal { - private _attachedHost: PortalHost | null; + private _attachedHost: PortalOutlet | null; /** Attach this portal to a host. */ - attach(host: PortalHost): T { + attach(host: PortalOutlet): T { if (host == null) { - throwNullPortalHostError(); + throwNullPortalOutletError(); } if (host.hasAttached()) { @@ -67,10 +67,10 @@ export abstract class Portal { } /** - * Sets the PortalHost reference without performing `attach()`. This is used directly by - * the PortalHost when it is performing an `attach()` or `detach()`. + * Sets the PortalOutlet reference without performing `attach()`. This is used directly by + * the PortalOutlet when it is performing an `attach()` or `detach()`. */ - setAttachedHost(host: PortalHost | null) { + setAttachedHost(host: PortalOutlet | null) { this._attachedHost = host; } } @@ -85,7 +85,7 @@ export class ComponentPortal extends Portal> { /** * [Optional] Where the attached component should live in Angular's *logical* component tree. - * This is different from where the component *renders*, which is determined by the PortalHost. + * This is different from where the component *renders*, which is determined by the PortalOutlet. * The origin is necessary when the host is outside of the Angular application context. */ viewContainerRef?: ViewContainerRef | null; @@ -130,11 +130,11 @@ export class TemplatePortal extends Portal { } /** - * Attach the the portal to the provided `PortalHost`. + * Attach the the portal to the provided `PortalOutlet`. * When a context is provided it will override the `context` property of the `TemplatePortal` * instance. */ - attach(host: PortalHost, context: C | undefined = this.context): C { + attach(host: PortalOutlet, context: C | undefined = this.context): C { this.context = context; return super.attach(host); } @@ -147,9 +147,9 @@ export class TemplatePortal extends Portal { /** - * A `PortalHost` is an space that can contain a single `Portal`. + * A `PortalOutlet` is an space that can contain a single `Portal`. */ -export interface PortalHost { +export interface PortalOutlet { attach(portal: Portal): any; detach(): any; @@ -161,10 +161,10 @@ export interface PortalHost { /** - * Partial implementation of PortalHost that only deals with attaching either a + * Partial implementation of PortalOutlet that only deals with attaching either a * ComponentPortal or a TemplatePortal. */ -export abstract class BasePortalHost implements PortalHost { +export abstract class BasePortalOutlet implements PortalOutlet { /** The portal currently attached to the host. */ private _attachedPortal: Portal | null; @@ -189,7 +189,7 @@ export abstract class BasePortalHost implements PortalHost { } if (this._isDisposed) { - throwPortalHostAlreadyDisposedError(); + throwPortalOutletAlreadyDisposedError(); } if (portal instanceof ComponentPortal) { diff --git a/src/cdk/portal/public-api.ts b/src/cdk/portal/public-api.ts index ff3db2670fd8..cad046f323ea 100644 --- a/src/cdk/portal/public-api.ts +++ b/src/cdk/portal/public-api.ts @@ -7,6 +7,10 @@ */ export * from './portal'; -export * from './dom-portal-host'; +export * from './dom-portal-outlet'; export * from './portal-directives'; export * from './portal-injector'; + +export {DomPortalOutlet as DomPortalHost} from './dom-portal-outlet'; +export {PortalOutletDirective as PortalHostDirective} from './portal-directives'; +export {PortalOutlet as PortalHost, BasePortalOutlet as BasePortalHost} from './portal'; diff --git a/src/demo-app/portal/portal-demo.html b/src/demo-app/portal/portal-demo.html index ee17457ba788..1a19fe9bc91d 100644 --- a/src/demo-app/portal/portal-demo.html +++ b/src/demo-app/portal/portal-demo.html @@ -1,6 +1,6 @@ -

The portal host is here:

-
- +

The portal outlet is here:

+
+
diff --git a/src/lib/tabs/tab-body.spec.ts b/src/lib/tabs/tab-body.spec.ts index 83cf647816a4..4572e9f756fe 100644 --- a/src/lib/tabs/tab-body.spec.ts +++ b/src/lib/tabs/tab-body.spec.ts @@ -156,16 +156,16 @@ describe('MatTabBody', () => { it('should attach the content when centered and detach when not', fakeAsync(() => { fixture.componentInstance.position = 1; fixture.detectChanges(); - expect(fixture.componentInstance.tabBody._portalHost.hasAttached()).toBe(false); + expect(fixture.componentInstance.tabBody._portalOutlet.hasAttached()).toBe(false); fixture.componentInstance.position = 0; fixture.detectChanges(); - expect(fixture.componentInstance.tabBody._portalHost.hasAttached()).toBe(true); + expect(fixture.componentInstance.tabBody._portalOutlet.hasAttached()).toBe(true); fixture.componentInstance.position = 1; fixture.detectChanges(); flushMicrotasks(); // Finish animation and let it detach in animation done handler - expect(fixture.componentInstance.tabBody._portalHost.hasAttached()).toBe(false); + expect(fixture.componentInstance.tabBody._portalOutlet.hasAttached()).toBe(false); })); }); diff --git a/src/lib/tabs/tab-body.ts b/src/lib/tabs/tab-body.ts index 9eb53f5f7316..d2e14bcfd0dc 100644 --- a/src/lib/tabs/tab-body.ts +++ b/src/lib/tabs/tab-body.ts @@ -27,7 +27,7 @@ import { transition, AnimationEvent, } from '@angular/animations'; -import {TemplatePortal, PortalHostDirective} from '@angular/cdk/portal'; +import {TemplatePortal, PortalOutletDirective} from '@angular/cdk/portal'; import {Directionality, Direction} from '@angular/cdk/bidi'; @@ -87,8 +87,8 @@ export type MatTabBodyOriginState = 'left' | 'right'; ] }) export class MatTabBody implements OnInit, AfterViewChecked { - /** The portal host inside of this container into which the tab body content will be loaded. */ - @ViewChild(PortalHostDirective) _portalHost: PortalHostDirective; + /** The portal outlet inside of this container into which the tab body content will be loaded. */ + @ViewChild(PortalOutletDirective) _portalOutlet: PortalOutletDirective; /** Event emitted when the tab begins to animate towards the center as the active tab. */ @Output() _onCentering: EventEmitter = new EventEmitter(); @@ -144,8 +144,8 @@ export class MatTabBody implements OnInit, AfterViewChecked { * content if it is not already attached. */ ngAfterViewChecked() { - if (this._isCenterPosition(this._position) && !this._portalHost.hasAttached()) { - this._portalHost.attach(this._content); + if (this._isCenterPosition(this._position) && !this._portalOutlet.hasAttached()) { + this._portalOutlet.attach(this._content); } } @@ -158,7 +158,7 @@ export class MatTabBody implements OnInit, AfterViewChecked { _onTranslateTabComplete(e: AnimationEvent) { // If the end state is that the tab is not centered, then detach the content. if (!this._isCenterPosition(e.toState) && !this._isCenterPosition(this._position)) { - this._portalHost.detach(); + this._portalOutlet.detach(); } // If the transition to the center is complete, emit an event. diff --git a/src/lib/tabs/tab-group.html b/src/lib/tabs/tab-group.html index da2d053b913d..1340760e198d 100644 --- a/src/lib/tabs/tab-group.html +++ b/src/lib/tabs/tab-group.html @@ -16,7 +16,7 @@ - +