Skip to content

Commit 5962c93

Browse files
amcdnljelbourn
authored andcommitted
docs(demos): add more dialog demos (#5666)
1 parent d70a669 commit 5962c93

17 files changed

+180
-63
lines changed

src/lib/dialog/dialog.md

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ dialogRef.afterClosed().subscribe(result => {
2222
});
2323

2424
dialogRef.close('Pizza!');
25-
2625
```
2726

2827
Components created via `MdDialog` can _inject_ `MdDialogRef` and use it to close the dialog
@@ -45,25 +44,27 @@ If you want to share data with your dialog, you can use the `data` option to pas
4544

4645
```ts
4746
let dialogRef = dialog.open(YourDialog, {
48-
data: 'your data',
47+
data: { name: 'austin' },
4948
});
5049
```
5150

5251
To access the data in your dialog component, you have to use the MD_DIALOG_DATA injection token:
52+
5353
```ts
5454
import {Component, Inject} from '@angular/core';
5555
import {MD_DIALOG_DATA} from '@angular/material';
5656

5757
@Component({
5858
selector: 'your-dialog',
59-
template: 'passed in {{ data }}',
59+
template: 'passed in {{ data.name }}',
6060
})
61-
6261
export class YourDialog {
6362
constructor(@Inject(MD_DIALOG_DATA) public data: any) { }
6463
}
6564
```
6665

66+
<!-- example(dialog-data) -->
67+
6768
### Dialog content
6869
Several directives are available to make it easier to structure your dialog content:
6970

@@ -93,6 +94,8 @@ You can control which elements are tab stops with the `tabindex` attribute
9394
<button md-button tabindex="-1">Not Tabbable</button>
9495
```
9596

97+
<!-- example(dialog-content) -->
98+
9699
### AOT Compilation
97100

98101
Due to the dynamic nature of the `MdDialog`, and its usage of `ViewContainerRef#createComponent()`
@@ -116,7 +119,7 @@ that the AOT compiler knows to create the `ComponentFactory` for it.
116119

117120
entryComponents: [
118121
ExampleDialogComponent
119-
]
122+
],
120123

121124
providers: [],
122125
bootstrap: [AppComponent]
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<h2 md-dialog-title>Install Angular</h2>
2+
<md-dialog-content>
3+
<h3>DEVELOP ACROSS ALL PLATFORMS</h3>
4+
<p>Learn one way to build applications with Angular and reuse your code and abilities to build
5+
apps for any deployment target. For web, mobile web, native mobile and native desktop.</p>
6+
7+
<h3>SPEED & PERFORMANCE</h3>
8+
<p>Achieve the maximum speed possible on the Web Platform today, and take it further, via Web
9+
Workers and server-side rendering. Angular puts you in control over scalability. Meet huge data requirements
10+
by building data models on RxJS, Immutable.js or another push-model.</p>
11+
12+
<h3>INCREDIBLE TOOLING</h3>
13+
<p>Build features quickly with simple, declarative templates. Extend the template language with your own
14+
components and use a wide array of existing components. Get immediate Angular-specific help and feedback
15+
with nearly every IDE and editor. All this comes together so you can focus on building amazing apps rather
16+
than trying to make the code work.</p>
17+
18+
<h3>LOVED BY MILLIONS</h3>
19+
<p>From prototype through global deployment, Angular delivers the productivity and scalable infrastructure
20+
that supports Google's largest applications.</p>
21+
</md-dialog-content>
22+
<md-dialog-actions>
23+
<button md-button [md-dialog-close]="true" tabindex="1">Install</button>
24+
<button md-button md-dialog-close tabindex="-1">Cancel</button>
25+
</md-dialog-actions>
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<button md-button (click)="openDialog()">Open dialog</button>
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import {Component} from '@angular/core';
2+
import {MdDialog} from '@angular/material';
3+
4+
/**
5+
* @title Dialog with header, scrollable content and actions
6+
*/
7+
@Component({
8+
selector: 'dialog-content-example',
9+
templateUrl: 'dialog-content-example.html',
10+
})
11+
export class DialogContentExample {
12+
constructor(public dialog: MdDialog) {}
13+
14+
openDialog() {
15+
const dialogRef = this.dialog.open(DialogContentExampleDialog, {
16+
height: '350px'
17+
});
18+
19+
dialogRef.afterClosed().subscribe(result => {
20+
console.log(`Dialog result: ${result}`);
21+
});
22+
}
23+
}
24+
25+
@Component({
26+
selector: 'dialog-content-example-dialog',
27+
templateUrl: 'dialog-content-example-dialog.html',
28+
})
29+
export class DialogContentExampleDialog {}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<h1 md-dialog-title>Favorite Animal</h1>
2+
<div md-dialog-content>
3+
My favorite animal is:
4+
<ul>
5+
<li>
6+
<span *ngIf="data.animal === 'panda'">&#10003;</span> Panda
7+
</li>
8+
<li>
9+
<span *ngIf="data.animal === 'unicorn'">&#10003;</span> Unicorn
10+
</li>
11+
<li>
12+
<span *ngIf="data.animal === 'lion'">&#10003;</span> Lion
13+
</li>
14+
</ul>
15+
</div>
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/** No CSS for this example */
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<button md-button (click)="openDialog()">Open dialog</button>
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import {Component, Inject} from '@angular/core';
2+
import {MdDialog, MD_DIALOG_DATA} from '@angular/material';
3+
4+
/**
5+
* @title Injecting data when opening a dialog
6+
*/
7+
@Component({
8+
selector: 'dialog-data-example',
9+
templateUrl: 'dialog-data-example.html',
10+
})
11+
export class DialogDataExample {
12+
constructor(public dialog: MdDialog) {}
13+
14+
openDialog() {
15+
this.dialog.open(DialogDataExampleDialog, {
16+
data: {
17+
animal: 'panda'
18+
}
19+
});
20+
}
21+
}
22+
23+
@Component({
24+
selector: 'dialog-data-example-dialog',
25+
templateUrl: 'dialog-data-example-dialog.html',
26+
})
27+
export class DialogDataExampleDialog {
28+
constructor(@Inject(MD_DIALOG_DATA) public data: any) {}
29+
}
Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,11 @@
1-
<p> Hi, I'm a dialog! </p>
1+
<h1 md-dialog-title>Hi {{data.name}}</h1>
2+
<div md-dialog-content>
3+
<p>What's your favorite animal?</p>
4+
<md-input-container>
5+
<input mdInput tabindex="1" [(ngModel)]="data.animal">
6+
</md-input-container>
7+
</div>
8+
<div md-dialog-actions>
9+
<button md-button [md-dialog-close]="data.animal" tabindex="2">Ok</button>
10+
<button md-button (click)="onNoClick()" tabindex="-1">No Thanks</button>
11+
</div>
Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,13 @@
1-
<button md-button (click)="openDialog()">Open dialog</button>
1+
<ol>
2+
<li>
3+
<md-input-container>
4+
<input mdInput [(ngModel)]="name" placeholder="What's your name?">
5+
</md-input-container>
6+
</li>
7+
<li>
8+
<button md-raised-button (click)="openDialog()">Pick one</button>
9+
</li>
10+
<li *ngIf="animal">
11+
You chose: <i>{{animal}}</i>
12+
</li>
13+
</ol>
Lines changed: 29 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,46 @@
1-
import {Component} from '@angular/core';
2-
import {MdDialog} from '@angular/material';
1+
import {Component, Inject} from '@angular/core';
2+
import {MdDialog, MdDialogRef, MD_DIALOG_DATA} from '@angular/material';
33

44
/**
55
* @title Dialog Overview
66
*/
77
@Component({
88
selector: 'dialog-overview-example',
9-
templateUrl: 'dialog-overview-example.html',
9+
templateUrl: 'dialog-overview-example.html'
1010
})
1111
export class DialogOverviewExample {
12+
13+
animal: string;
14+
name: string;
15+
1216
constructor(public dialog: MdDialog) {}
1317

14-
openDialog() {
15-
this.dialog.open(DialogOverviewExampleDialog);
18+
openDialog(): void {
19+
let dialogRef = this.dialog.open(DialogOverviewExampleDialog, {
20+
width: '250px',
21+
data: { name: this.name, animal: this.animal }
22+
});
23+
24+
dialogRef.afterClosed().subscribe(result => {
25+
console.log('The dialog was closed');
26+
this.animal = result;
27+
});
1628
}
17-
}
1829

30+
}
1931

2032
@Component({
2133
selector: 'dialog-overview-example-dialog',
2234
templateUrl: 'dialog-overview-example-dialog.html',
2335
})
24-
export class DialogOverviewExampleDialog {}
36+
export class DialogOverviewExampleDialog {
37+
38+
constructor(
39+
public dialogRef: MdDialogRef<DialogOverviewExampleDialog>,
40+
@Inject(MD_DIALOG_DATA) public data: any) { }
41+
42+
onNoClick(): void {
43+
this.dialogRef.close();
44+
}
45+
46+
}

src/material-examples/dialog-result/dialog-result-example-dialog.html

Lines changed: 0 additions & 6 deletions
This file was deleted.

src/material-examples/dialog-result/dialog-result-example.html

Lines changed: 0 additions & 2 deletions
This file was deleted.

src/material-examples/dialog-result/dialog-result-example.ts

Lines changed: 0 additions & 31 deletions
This file was deleted.

src/material-examples/example-module.ts

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,10 @@ import {DatepickerMinMaxExample} from './datepicker-min-max/datepicker-min-max-e
3131
import {DatepickerOverviewExample} from './datepicker-overview/datepicker-overview-example';
3232
import {DatepickerStartViewExample} from './datepicker-start-view/datepicker-start-view-example';
3333
import {DatepickerTouchExample} from './datepicker-touch/datepicker-touch-example';
34+
import {DialogContentExampleDialog,DialogContentExample} from './dialog-content/dialog-content-example';
35+
import {DialogDataExampleDialog,DialogDataExample} from './dialog-data/dialog-data-example';
3436
import {DialogElementsExampleDialog,DialogElementsExample} from './dialog-elements/dialog-elements-example';
3537
import {DialogOverviewExampleDialog,DialogOverviewExample} from './dialog-overview/dialog-overview-example';
36-
import {DialogResultExampleDialog,DialogResultExample} from './dialog-result/dialog-result-example';
3738
import {GridListDynamicExample} from './grid-list-dynamic/grid-list-dynamic-example';
3839
import {GridListOverviewExample} from './grid-list-overview/grid-list-overview-example';
3940
import {IconOverviewExample} from './icon-overview/icon-overview-example';
@@ -189,6 +190,18 @@ export const EXAMPLE_COMPONENTS = {
189190
additionalFiles: null,
190191
selectorName: null
191192
},
193+
'dialog-content': {
194+
title: 'Dialog with header, scrollable content and actions',
195+
component: DialogContentExample,
196+
additionalFiles: ["dialog-content-example-dialog.html"],
197+
selectorName: 'DialogContentExample, DialogContentExampleDialog'
198+
},
199+
'dialog-data': {
200+
title: 'Injecting data when opening a dialog',
201+
component: DialogDataExample,
202+
additionalFiles: ["dialog-data-example-dialog.html"],
203+
selectorName: 'DialogDataExample, DialogDataExampleDialog'
204+
},
192205
'dialog-elements': {
193206
title: 'Dialog elements',
194207
component: DialogElementsExample,
@@ -201,12 +214,6 @@ export const EXAMPLE_COMPONENTS = {
201214
additionalFiles: ["dialog-overview-example-dialog.html"],
202215
selectorName: 'DialogOverviewExample, DialogOverviewExampleDialog'
203216
},
204-
'dialog-result': {
205-
title: 'Dialog with a result',
206-
component: DialogResultExample,
207-
additionalFiles: ["dialog-result-example-dialog.html"],
208-
selectorName: 'DialogResultExample, DialogResultExampleDialog'
209-
},
210217
'grid-list-dynamic': {
211218
title: 'Dynamic grid-list',
212219
component: GridListDynamicExample,
@@ -498,9 +505,10 @@ export const EXAMPLE_LIST = [
498505
DatepickerOverviewExample,
499506
DatepickerStartViewExample,
500507
DatepickerTouchExample,
508+
DialogContentExampleDialog,DialogContentExample,
509+
DialogDataExampleDialog,DialogDataExample,
501510
DialogElementsExampleDialog,DialogElementsExample,
502511
DialogOverviewExampleDialog,DialogOverviewExample,
503-
DialogResultExampleDialog,DialogResultExample,
504512
GridListDynamicExample,
505513
GridListOverviewExample,
506514
IconOverviewExample,

src/material-examples/material-module.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,12 @@ import {
3535
MdSliderModule,
3636
MdSidenavModule,
3737
MdSnackBarModule,
38-
MdTableModule,
3938
MdTabsModule,
4039
MdToolbarModule,
4140
MdTooltipModule,
4241
MdPaginatorModule,
43-
MdSortModule
42+
MdSortModule,
43+
MdTableModule
4444
]
4545
})
4646
export class ExampleMaterialModule {}

0 commit comments

Comments
 (0)