Skip to content

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

Merged
merged 6 commits into from
Apr 17, 2017

Conversation

M-a-c
Copy link
Contributor

@M-a-c M-a-c commented Apr 4, 2017

@googlebot googlebot added the cla: yes PR author has agreed to Google's Contributor License Agreement label Apr 4, 2017
})

export class DialogName {
constructor@Inject(MD_DIALOG_DATA) public data: any) { }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

missing (

Copy link
Contributor Author

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..

@@ -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).
Copy link
Member

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.

Copy link
Contributor Author

@M-a-c M-a-c Apr 6, 2017

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)

Copy link
Member

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.

})

export class DialogName {
constructor( @Inject(MD_DIALOG_DATA) public data: any ) { }
Copy link
Member

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) { }.


Passing outside data to your component is as simple as.
```ts
import {MdDialog} from '@angular/material';
Copy link
Member

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.

private dialog: MdDialog;

let dialogRef = dialog.open(DialogName, {
data:'your data',
Copy link
Member

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.

Here is an example component you can pass data to.
```ts
import {Component, Inject} from '@angular/core';
import {MD_DIALOG_DATA} from '@angular/material';
Copy link
Member

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok

import {MD_DIALOG_DATA} from '@angular/material';

@Component({
selector: 'dialog-selector',
Copy link
Member

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.

@@ -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.
Copy link
Member

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".

@@ -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.
Copy link
Member

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.

});
```

Here is an example component you can pass data to.
Copy link
Member

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:"?

constructor(@Inject(MD_DIALOG_DATA) public data: any) { }
}
```

Copy link
Member

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.

@M-a-c
Copy link
Contributor Author

M-a-c commented Apr 13, 2017

Yeah your wording is a lot more crisp. I need to work on this my wording before I make more contributions.
Short sweet and to the point. Thanks for being patient crisbeto.

Copy link
Member

@crisbeto crisbeto left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@crisbeto crisbeto added pr: lgtm action: merge The PR is ready for merge by the caretaker labels Apr 14, 2017
@henriquefm
Copy link

Just a small detail: the name of the dialog class in dialog.open(DialogName, ... (line 36) is different from the actual class on line 51, export class YourDialog.

@jelbourn jelbourn merged commit 9f2c7ac into angular:master Apr 17, 2017
@M-a-c M-a-c deleted the dialogRef-data-in branch April 17, 2017 19:20
@angular-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Sep 6, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
action: merge The PR is ready for merge by the caretaker cla: yes PR author has agreed to Google's Contributor License Agreement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Documentation is unclear about how to get data into a Dialog.
6 participants