Skip to content

Commit 9f2c7ac

Browse files
M-a-cjelbourn
authored andcommitted
docs(dialog): address injecting dialog data (#3907)
1 parent 5c3278a commit 9f2c7ac

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

src/lib/dialog/dialog.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,30 @@ Components created via `MdDialog` can _inject_ `MdDialogRef` and use it to close
2929
in which they are contained. When closing, an optional result value can be provided. This result
3030
value is forwarded as the result of the `afterClosed` promise.
3131

32+
### Sharing data with the Dialog component.
33+
If you want to share data with your dialog, you can use the `data` option to pass information to the dialog component.
34+
35+
```ts
36+
let dialogRef = dialog.open(YourDialog, {
37+
data: 'your data',
38+
});
39+
```
40+
41+
To access the data in your dialog component, you have to use the MD_DIALOG_DATA injection token:
42+
```ts
43+
import {Component, Inject} from '@angular/core';
44+
import {MD_DIALOG_DATA} from '@angular/material';
45+
46+
@Component({
47+
selector: 'your-dialog',
48+
template: 'passed in {{ data }}',
49+
})
50+
51+
export class YourDialog {
52+
constructor(@Inject(MD_DIALOG_DATA) public data: any) { }
53+
}
54+
```
55+
3256
### Dialog content
3357
Several directives are available to make it easier to structure your dialog content:
3458

0 commit comments

Comments
 (0)