Documentation bug.
When I use the MdDialog service to open a dialog with some component, I'd love to be able to pass some configuration into that component.
The dialogRef exposes componentInstance, which allows me to set properties / call functions on the component after construction, however I'm unsure if this is the recommended approach since it is not mentioned in the docs.
Read the docs at https://github.com/angular/material2/blob/master/src/lib/dialog/README.md, and notice the example uses a "static" dialog.
It would improve the documentation and reduce the number of future issues.
Latest /all
I can submit a PR for improved documentation of an answer from this threads provides sufficient information!
The dialogRef exposes componentInstance, which allows me to set properties / call functions on the component after construction, however I'm unsure if this is the recommended approach since it is not mentioned in the docs.
https://github.com/angular/material2/issues/1377#issuecomment-250632661
@SamMousa, as I see it's actually the only way to do it directly. You can use an injected service for that, but, IMHO, it would be an overkill.
I've added this to my todo list.
Is there any timeframe of when this will be added? if not could a code snippet be created here to show how to do it?
@tmburnell I'm currently no longer working on an angular related project so it's low on the list.
I figured it out from another post:
use this when opening
let dialogRef = this.dialog.open(myModal);
dialogRef.componentInstance.data = myData;
use this in the modal
ngOnInit() {
this.data = this.dialogRef.componentInstance.data;
}
@SamMousa
I know in general components should share data (typically modeled data) with a service. (depending on what you're doing) But Yeah the docs dont really show how to pass data in, I'm getting a pr in for that.
https://angular.io/docs/ts/latest/cookbook/component-communication.html#!#bidirectional-service
@tmburnell this is the way I found it used in the source.
https://plnkr.co/edit/vpTaIAdIJnjd7ngFG2Ea?p=preview
I'm gonna close this since I no longer expect I'll be working on it in the foreseeable future.
@SamMousa I have a PR out for this, you were right about it being confusing. I'm trying to fix that in the docs.
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._
Most helpful comment
I figured it out from another post:
use this when opening
use this in the modal