Skip to content

MdDialog communication (i.e: passing data to MdDialog) #2181

Closed
@shlomiassaf

Description

@shlomiassaf

Bug, feature request, or proposal: Proposal

What is the expected behavior?

Pass data to a component opened by the dialog service without depending on the dialog instance.

What is the current behavior?

You can pass data to a component by accessing it's instance and setting a predefined property.

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

There are several ways to communicate with a dialog component:

  1. Custom Dependency injection - Set Providers as part of the options
  2. Fixed Dependency injection - Set a single data item as part of the options, injected via a token.
  3. MdDialogRef as a carrier - Set a single data item as part of the options, component consumed via MdDialogRef.data.
  4. Direct assignment - Current behavior

The current behavior allow (4) and a limited (1)

(1) Only predefined providers.

It does not fit the angular pattern.

Angular uses DI a lot, this is part of the flow.

  • Automatic errors if DI mismatch
  • Allows proper use of hooks
  • Less dependant

Since the dialog service abstract the component instantiation there is no control over the providers.
However, this process does allow changing providers by supplying an injector...

So all in all I think it should be possible to get some sort of control over the DI.

Workaround:

My current workaround is to create a service wrapping MdDialog.
This services uses a wrapper component as the Component to create.
The wrapper component then create the original component inside it with the supplied providers.

Metadata

Metadata

Assignees

Labels

featureThis issue represents a new feature or feature request rather than a bug or bug fix

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions