import {Component, AfterViewInit, TemplateRef, ViewChild, ViewContainerRef} from '@angular/core'; import {ComponentPortal, Portal, TemplatePortal} from '@angular/cdk/portal'; /** * @title Portal overview */ @Component({ selector: 'cdk-portal-overview-example', templateUrl: 'cdk-portal-overview-example.html', styleUrls: ['cdk-portal-overview-example.css'], }) export class CdkPortalOverviewExample implements AfterViewInit { @ViewChild('templatePortalContent', {static: false}) templatePortalContent: TemplateRef; selectedPortal: Portal; componentPortal: ComponentPortal; templatePortal: TemplatePortal; constructor(private _viewContainerRef: ViewContainerRef) {} ngAfterViewInit() { this.componentPortal = new ComponentPortal(ComponentPortalExample); this.templatePortal = new TemplatePortal(this.templatePortalContent, this._viewContainerRef); } } @Component({ selector: 'component-portal-example', template: 'Hello, this is a component portal' }) export class ComponentPortalExample {}