Skip to content

Commit 77f568b

Browse files
crisbetoandrewseguin
authored andcommitted
docs(portal): add overview example (#14655)
Adds a basic overview example for the `cdk/portal` package since it doesn't have any live examples.
1 parent 326f8bb commit 77f568b

File tree

5 files changed

+50
-0
lines changed

5 files changed

+50
-0
lines changed

src/cdk/portal/portal.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ a `PortalOutlet`.
99
Portals and PortalOutlets are low-level building blocks that other concepts, such as overlays, are
1010
built upon.
1111

12+
<!-- example(cdk-portal-overview) -->
13+
1214
##### `Portal<T>`
1315
| Method | Description |
1416
| --------------------------- | ----------------------------------- |
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
.example-portal-outlet {
2+
margin-bottom: 10px;
3+
padding: 10px;
4+
border: 1px dashed black;
5+
width: 250px;
6+
height: 250px;
7+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<h2>The portal outlet is below:</h2>
2+
<div class="example-portal-outlet">
3+
<ng-template [cdkPortalOutlet]="selectedPortal"></ng-template>
4+
</div>
5+
<ng-template #templatePortalContent>Hello, this is a template portal</ng-template>
6+
7+
<button (click)="selectedPortal = componentPortal">Render component portal</button>
8+
<button (click)="selectedPortal = templatePortal">Render template portal</button>
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import {Component, AfterViewInit, TemplateRef, ViewChild, ViewContainerRef} from '@angular/core';
2+
import {ComponentPortal, Portal, TemplatePortal} from '@angular/cdk/portal';
3+
4+
/**
5+
* @title Portal overview
6+
*/
7+
@Component({
8+
selector: 'cdk-portal-overview-example',
9+
templateUrl: 'cdk-portal-overview-example.html',
10+
styleUrls: ['cdk-portal-overview-example.css'],
11+
})
12+
export class CdkPortalOverviewExample implements AfterViewInit {
13+
@ViewChild('templatePortalContent') templatePortalContent: TemplateRef<any>;
14+
selectedPortal: Portal<any>;
15+
componentPortal: ComponentPortal<ComponentPortalExample>;
16+
templatePortal: TemplatePortal<any>;
17+
18+
constructor(private _viewContainerRef: ViewContainerRef) {}
19+
20+
ngAfterViewInit() {
21+
this.componentPortal = new ComponentPortal(ComponentPortalExample);
22+
this.templatePortal = new TemplatePortal(this.templatePortalContent, this._viewContainerRef);
23+
}
24+
}
25+
26+
@Component({
27+
selector: 'component-portal-example',
28+
template: 'Hello, this is a component portal'
29+
})
30+
export class ComponentPortalExample {}

src/material-examples/material-module.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import {A11yModule} from '@angular/cdk/a11y';
55
import {CdkTableModule} from '@angular/cdk/table';
66
import {CdkTreeModule} from '@angular/cdk/tree';
77
import {DragDropModule} from '@angular/cdk/drag-drop';
8+
import {PortalModule} from '@angular/cdk/portal';
89
import {
910
MatAutocompleteModule, MatBadgeModule, MatBottomSheetModule, MatButtonModule,
1011
MatButtonToggleModule, MatCardModule, MatCheckboxModule, MatChipsModule, MatDatepickerModule,
@@ -57,6 +58,7 @@ import {
5758
MatTooltipModule,
5859
MatTreeModule,
5960
ScrollingModule,
61+
PortalModule,
6062
],
6163
exports: [
6264
A11yModule,
@@ -99,6 +101,7 @@ import {
99101
MatTooltipModule,
100102
MatTreeModule,
101103
ScrollingModule,
104+
PortalModule,
102105
]
103106
})
104107
export class ExampleMaterialModule {}

0 commit comments

Comments
 (0)