-
Notifications
You must be signed in to change notification settings - Fork 6.8k
Docs (DialogMd data input): addresses confusion with injecting data #3907
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
src/lib/dialog/dialog.md
Outdated
}) | ||
|
||
export class DialogName { | ||
constructor@Inject(MD_DIALOG_DATA) public data: any) { } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
missing (
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LOL how on earth? Must have hit the backspace key switching just before commit, that's super weird..
src/lib/dialog/dialog.md
Outdated
@@ -29,6 +29,33 @@ 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. | |||
Depending on what you are doing you might want to share data with your dialog component. Angular has documentation that explains in general how to share data between any components using [`services`](https://angular.io/docs/ts/latest/cookbook/component-communication.html#!#bidirectional-service). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think we should talk about services here, because they're a general Angular pattern. We should mention the data
option instead.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah I agree. Should that ever be addressed in Angular Material documentation? Since a lot of the components are interactive, services seem pretty fundamental to the 'passing data problem' I started with Angular 3 months ago, and I was introduced to services by a few other developers asking why I was doing everything so backwards. I'm glad they brought it up, because in the long run it made my code a lot easier to understand.
- Is there a spot that we could expose users to services? (lots of us are beginners)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think it's Material's responsibility to expose users to services.
src/lib/dialog/dialog.md
Outdated
}) | ||
|
||
export class DialogName { | ||
constructor( @Inject(MD_DIALOG_DATA) public data: any ) { } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't do spaces between the braces. It should be constructor(@Inject(MD_DIALOG_DATA) public data: any) { }
.
src/lib/dialog/dialog.md
Outdated
|
||
Passing outside data to your component is as simple as. | ||
```ts | ||
import {MdDialog} from '@angular/material'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In this example it's pretty obvious where MdDialog
comes from so you can remove this line and the private dialog: MdDialog
.
src/lib/dialog/dialog.md
Outdated
private dialog: MdDialog; | ||
|
||
let dialogRef = dialog.open(DialogName, { | ||
data:'your data', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add a space between the :
and the string.
src/lib/dialog/dialog.md
Outdated
Here is an example component you can pass data to. | ||
```ts | ||
import {Component, Inject} from '@angular/core'; | ||
import {MD_DIALOG_DATA} from '@angular/material'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can leave the imports here since the injection is slightly more convoluted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok
src/lib/dialog/dialog.md
Outdated
import {MD_DIALOG_DATA} from '@angular/material'; | ||
|
||
@Component({ | ||
selector: 'dialog-selector', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Try renaming this to something like your-dialog
and the class to YourDialog
.
src/lib/dialog/dialog.md
Outdated
@@ -29,6 +29,37 @@ 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. | |||
Depending on what you are doing you might want to share data with your dialog component. The dialog component has a data option that you can include in order to pass data from the open to the dialog. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You should add backticks(`) around "data" in "The dialog component has a data option".
src/lib/dialog/dialog.md
Outdated
@@ -29,6 +29,33 @@ 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. | |||
Depending on what you are doing you might want to share data with your dialog component. The dialog component has a `data` option allowing you to pass data to the component. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry for all the requests, but can you reword this to "If you want to share data with your dialog, you can use the data
option to pass information to the dialog component.". Also if you remove the "Passing outside data to your component is as simple as." sentence the PR will be good to go.
src/lib/dialog/dialog.md
Outdated
}); | ||
``` | ||
|
||
Here is an example component you can pass data to. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you change this to "To access the data
in your dialog component, you have to use the MD_DIALOG_DATA
injection token:"?
src/lib/dialog/dialog.md
Outdated
constructor(@Inject(MD_DIALOG_DATA) public data: any) { } | ||
} | ||
``` | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you reduce the amount of extra blank lines here? This is mainly for consistency.
Yeah your wording is a lot more crisp. I need to work on this my wording before I make more contributions. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Just a small detail: the name of the dialog class in |
This issue has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
Fixes Documentation is unclear about how to get data into a Dialog. #1947