Skip to content
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

[Bug|self error] md-select in md-dialog can't use providers data #2374

Closed
luchillo17 opened this issue Dec 23, 2016 · 8 comments
Closed

[Bug|self error] md-select in md-dialog can't use providers data #2374

luchillo17 opened this issue Dec 23, 2016 · 8 comments

Comments

@luchillo17
Copy link

luchillo17 commented Dec 23, 2016

Bug, feature request, or proposal:

Bug or misconfiguration.

What is the expected behavior?

I was expecting the dialog component to have available the same service instance of the caller(parent) component, but that service is local to the caller(parent) component, after that i request some data and put that in the md-select, and set a default.

I set the default value from the caller(parent) component through the instance of the dialog component.

What is the current behavior?

I'm forced to open the dialog, get the dialog instance and set the service manually instead of asking for it to the injector.

However it doesn't end there, i had to set the value from the parent component, then in the dialog component was getting the select data from service, but the default selected value wasn't being set.

I'm forced to both pass the default selected value as well as the options data from the parent through the instance of the dialog component.

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

Harder to deal with if we need to set everything from the parent through the instance of the dialog component instead of using the injector.

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

Angular: 2.2.1
Material: 2.0.0-beta.0
Browser: Chrome 55.0.2883.95

Is there anything else we should know?

I suspect it has to do with the value being set before the data for the select is available.

Maybe the value set from the parent through instance is outside of the ngZone?

Scratch the last sentence, it is in the zone since it works when i set all from the parent through the instance of the md-dialog component.

@luchillo17
Copy link
Author

@icordoba8 take a look.

@EladBezalel
Copy link
Member

Can you please provide a codepen so we can investigate further?

@luchillo17
Copy link
Author

luchillo17 commented Jan 12, 2017

@EladBezalel Can you give me a base pen to start?

@EladBezalel
Copy link
Member

Plunker : http://plnkr.co/edit/o077B6uEiiIgkC0S06dd :)

@luchillo17
Copy link
Author

luchillo17 commented Jan 12, 2017

Ok here it is, Plunkr local service, just click the button that says showDialog, then it should show an error in console like this:
image

Please note that the service is local to the CustomerComponent component, instead of a singleton provider it would be if it were a provider declared in main.ts in the AppModule.

In such case we were forced to deal with it like this, setting the service through the dialogRef's component instance directly, is this the correct way of dealing with it?:

showDialog() {
    this.dialogRef = this.dialog.open(CustomerDialogComponent, {
      disableClose: false
    });

    this.dialogRef.componentInstance.customerService = this.customerService;

    this.dialogRef.afterClosed().subscribe(result => {
      console.log('result: ' + result);
      this.dialogRef = null;
    });
  }

@EladBezalel
Copy link
Member

Took me a while to realize you forgot to include your service as a provider 😅
http://plnkr.co/edit/iDSXXjKxY7QNqO7ABCe6?p=preview

@luchillo17
Copy link
Author

luchillo17 commented Jan 13, 2017

For the love of ...

You didn't understand my point, i don't want a singleton provider available to the full app, i want a local provider to the customer component.

Originally in my project there is an OrderListComponent, which could have multiple instances of OrderComponent, thus multiple OrderService instances as well (one for each component).

The issue is that the local provider isn't available to the Dialog even if the parent that instantiated the Dialog does have access to the provider.

I mean, did you look at the CustomerComponent providers section in my pen? maybe should i have used an Order analogy with 2 different instances?
image

I want to be able to have multiple component instances, each instance would have it's own Provider, and when opening the Dialog, the Dialog should have access to the Provider instance of the parent (or the Provider of the component that opened the Dialog).

@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 5, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants