Skip to content

Documentation is unclear about how to get data into a Dialog. #1947

Closed

Description

@SamMousa

Bug, feature request, or proposal:

Documentation bug.

What is the expected behavior?

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.

What is the current behavior?

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.

What are the steps to reproduce?

Read the docs at https://github.com/angular/material2/blob/master/src/lib/dialog/README.md, and notice the example uses a "static" dialog.

What is the use-case or motivation for changing an existing behavior?

It would improve the documentation and reduce the number of future issues.

Which versions of Angular, Material, OS, browsers are affected?

Latest /all

Is there anything else we should know?

I can submit a PR for improved documentation of an answer from this threads provides sufficient information!

Activity

  1. DzmitryShylovich commented on Nov 23, 2016

    @DzmitryShylovich

    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.

    #1377 (comment)

  2. added
    docs
    help wanted
    on Nov 30, 2016
  3. eagle-dan1349 commented on Nov 30, 2016

    @eagle-dan1349

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

  4. SamMousa commented on Dec 8, 2016

    @SamMousa
    Author

    I've added this to my todo list.

  5. tmburnell commented on Feb 13, 2017

    @tmburnell

    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?

  6. SamMousa commented on Feb 13, 2017

    @SamMousa
    Author

    @tmburnell I'm currently no longer working on an angular related project so it's low on the list.

  7. tmburnell commented on Feb 14, 2017

    @tmburnell

    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;
    }
    
  8. M-a-c commented on Apr 4, 2017

    @M-a-c
    Contributor

    @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

  9. SamMousa commented on Apr 5, 2017

    @SamMousa
    Author

    I'm gonna close this since I no longer expect I'll be working on it in the foreseeable future.

  10. M-a-c commented on Apr 5, 2017

    @M-a-c
    Contributor

    @SamMousa I have a PR out for this, you were right about it being confusing. I'm trying to fix that in the docs.

  11. angular-automatic-lock-bot commented on Sep 5, 2019

    @angular-automatic-lock-bot

    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.

  12. locked and limited conversation to collaborators on Sep 5, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    docshelp wanted

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions