mirror of
https://github.com/angular/angular.git
synced 2026-09-14 13:54:52 +08:00
docs(dialog): address injecting dialog data (#3907)
This commit is contained in:
@@ -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:
|
||||
|
||||
|
||||
Reference in New Issue
Block a user