From 9f2c7aca2e8fb5a64ff8615b8a25ad2e495f6d08 Mon Sep 17 00:00:00 2001 From: Mac Date: Mon, 17 Apr 2017 11:40:57 -0700 Subject: [PATCH] docs(dialog): address injecting dialog data (#3907) --- src/lib/dialog/dialog.md | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/src/lib/dialog/dialog.md b/src/lib/dialog/dialog.md index 622f4b72429..70272dd6aae 100644 --- a/src/lib/dialog/dialog.md +++ b/src/lib/dialog/dialog.md @@ -29,6 +29,30 @@ Components created via `MdDialog` can _inject_ `MdDialogRef` and use it to close in which they are contained. When closing, an optional result value can be provided. This result value is forwarded as the result of the `afterClosed` promise. +### Sharing data with the Dialog component. +If you want to share data with your dialog, you can use the `data` option to pass information to the dialog component. + +```ts +let dialogRef = dialog.open(YourDialog, { + data: 'your data', +}); +``` + +To access the data in your dialog component, you have to use the MD_DIALOG_DATA injection token: +```ts +import {Component, Inject} from '@angular/core'; +import {MD_DIALOG_DATA} from '@angular/material'; + +@Component({ + selector: 'your-dialog', + template: 'passed in {{ data }}', +}) + +export class YourDialog { + constructor(@Inject(MD_DIALOG_DATA) public data: any) { } +} +``` + ### Dialog content Several directives are available to make it easier to structure your dialog content: