-
Notifications
You must be signed in to change notification settings - Fork 6.8k
How to pass data to material dialog #2031
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
Comments
There is not an easy way, as the only thing dialog supports now is creating a new component you pass it... so the best thing you can do is to inject some service inside that component and get the data that way. Once this is done https://github.com/angular/material2/blob/master/src/lib/dialog/dialog.ts#L23 you'll probably be able to simply pass it an existing component with standard binding.. if you don't want to wait for it to happen, you can use this simple modal component I put together using material2 overlay/portal utils https://gist.github.com/fxck/9ab983b80aca197ff22c29c0dfa6daf6 it's stateless(as I keep state of my modals inside https://github.com/ngrx/store) and works like this <cpt-modal
[open]="addModalState$ | async"
(close)="onModalClose$.next($event)">
<!-- whatever you want here -->
<md-card>
<cpt-brand-form
#brandFormRef
[form]="form"
[people]="internalPeople$ | async"
(update)="onAdd$.next($event)">
</cpt-brand-form>
</md-card>
</cpt-modal> |
Have you tried the suggestion from here? |
Thanks for your answers ;) |
Okay, I had a same problem but I found solution. You can put inside your dialog.open() function
And then inside your dialog component you can get the data:
|
Yes it's work ;) Have a nice day. |
i guys can i get an example code of this |
That was a bit much to find all the pieces necessary to pass the data, and the newest version was missing some helpful type annotations (I looked at the version closest to the date of the previous comment). I'll sum up. The dialog initiator opens the dialog and passes config(of type MdDialogConfig(found at the same location as the dialog definition)), with a property called data on it.
and the dialog component gets the data injected into it's constructor.
I didn't like having the data be any (I like types), so I exported an interface from my dialog, and used that for the type of config.data instead of any. |
how do i pass 2 formgroups with the data:{} into the dialog. i am able to pass 1 of them.... and if you change a formcontrol in the passed data does it retain the change when the dialog is closed ? to show in the component that opened the dialog? |
You can do something like:
And access the data using
|
excellent i will try that. thank you.
is the data 2 way bound , meaning if i change a value for example data.form1.controls(‘item’).patchvalue(‘test’)
that kind of code. would the data from the component we passed from change? or does the data inside the dialog not link to the original data?
… On 27 Oct 2017, at 13:03, Dushko Stanoeski ***@***.***> wrote:
You can do something like:
{
data: {
form1: {
...
},
form2: {
...
}
}
}
And access the data using
this.data.form1
this.data.form2
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub <#2031 (comment)>, or mute the thread <https://github.com/notifications/unsubscribe-auth/APRoAzCJs31pl4Kyjih_1TXwixK5tQ_Qks5swbiZgaJpZM4K_-uS>.
|
Just looking into dialog and trying to understand why MAT_DIALOG_DATA exists when you have the componentInstance to pass in data via inputs, of which are type protected. Did MAT_DIALOG_DATA come before or after the componentInstance? I've come from ng-bootstrap so am more inclined to use the componentInstance to pass in data but am wondering if it solves some other problem I don't know about yet |
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. |
Uh oh!
There was an error while loading. Please reload this page.
Hi all,
Someone can provide me an example of Dialog with param please ?
Thanks a lot.
The text was updated successfully, but these errors were encountered: