Skip to content

Commit c9ef34c

Browse files
feloykara
authored andcommitted
docs(dialog): document MdDialog (#1569)
1 parent da2af1e commit c9ef34c

File tree

2 files changed

+90
-1
lines changed

2 files changed

+90
-1
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ High level items planned for October 2016:
6161
| menu | Initial version, needs enhancements | [README][17] | [#119][0119] |
6262
| tooltip | Initial version, needs enhancements | [README][18] | - |
6363
| ripples | Available, but needs to be applied | [README][19] | [#108][0108] |
64-
| dialog | Started, not yet ready for release | - | [#114][0114] |
64+
| dialog | Started, not yet ready for release | [README][22] | [#114][0114] |
6565
| snackbar / toast | Initial version, needs enhancements | [README][21] | [#115][0115] |
6666
| select | Design started | - | [#118][0118] |
6767
| textarea | Not started | - | [#546][0546] |
@@ -102,6 +102,7 @@ High level items planned for October 2016:
102102
[19]: https://github.com/angular/material2/blob/master/src/lib/core/ripple/README.md
103103
[20]: https://github.com/angular/material2/blob/master/docs/theming.md
104104
[21]: https://github.com/angular/material2/blob/master/src/lib/snack-bar/README.md
105+
[22]: https://github.com/angular/material2/blob/master/src/lib/dialog/README.md
105106

106107
[0107]: https://github.com/angular/material2/issues/107
107108
[0119]: https://github.com/angular/material2/issues/119

src/lib/dialog/README.md

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
# MdDialog
2+
3+
MdDialog is a service, which opens dialogs components in the view.
4+
5+
### Methods
6+
7+
| Name | Description |
8+
| --- | --- |
9+
| `open(component: ComponentType<T>, config: MdDialogConfig): MdDialogRef<T>` | Creates and opens a dialog matching material spec. |
10+
11+
### Config
12+
13+
| Key | Description |
14+
| --- | --- |
15+
| `viewContainerRef: ViewContainerRef` | The view container ref to attach the dialog to. |
16+
| `role: DialogRole = 'dialog'` | The ARIA role of the dialog element. Possible values are `dialog` and `alertdialog`. Defaults to `dialog`. |
17+
18+
## MdDialogRef
19+
20+
A reference to the dialog created by the MdDialog `open` method.
21+
22+
### Methods
23+
24+
| Name | Description |
25+
| --- | --- |
26+
| `close(dialogResult?: any)` | Closes the dialog, pushing a value to the afterClosed observable. |
27+
| `afterClosed(): Observable<any>` | Returns an observable which will emit the dialog result, passed to the `close` method above. |
28+
29+
## Example
30+
The service can be injected in a component.
31+
32+
```ts
33+
@Component({
34+
selector: 'pizza-component',
35+
template: `
36+
<button type="button" (click)="openDialog()">Open dialog</button>
37+
`
38+
})
39+
export class PizzaComponent {
40+
41+
dialogRef: MdDialogRef<PizzaDialog>;
42+
43+
constructor(
44+
public dialog: MdDialog,
45+
public viewContainerRef: ViewContainerRef) { }
46+
47+
openDialog() {
48+
let config = new MdDialogConfig();
49+
config.viewContainerRef = this.viewContainerRef;
50+
51+
this.dialogRef = this.dialog.open(PizzaDialog, config);
52+
53+
this.dialogRef.afterClosed().subscribe(result => {
54+
console.log('result: ' + result);
55+
this.dialogRef = null;
56+
});
57+
}
58+
}
59+
60+
@Component({
61+
selector: 'pizza-dialog',
62+
template: `
63+
<button type="button" (click)="dialogRef.close('yes')">Yes</button>
64+
<button type="button" (click)="dialogRef.close('no')">No</button>
65+
`
66+
})
67+
export class PizzaDialog {
68+
constructor(public dialogRef: MdDialogRef<PizzaDialog>) { }
69+
}
70+
```
71+
72+
The dialog component should be declared in the list of entry components of the module:
73+
74+
```ts
75+
@NgModule({
76+
declarations: [
77+
...,
78+
PizzaDialog
79+
],
80+
entryComponents: [
81+
...,
82+
PizzaDialog
83+
],
84+
...
85+
})
86+
export class AppModule { }
87+
88+
```

0 commit comments

Comments
 (0)