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>

0 commit comments

Comments
 (0)