-
Notifications
You must be signed in to change notification settings - Fork 6.7k
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
Providers no longer injected in Components instantiated through MatDialog.open() #25073
Comments
Transferring to components repo because I suspect this is not caused by the FW, but rather a change in the Material components. |
@JoostK: Yeah, I was 50/50 about that. Picked the more general project. |
The dialog likely worked like this by accident, we didn't put in any intention on where DI would be resolved from by default. In fb9ff16 the services were rewritten to reuse more code which probably moved around the DI tree as well. You can get the old behavior by passing in the
|
@crisbeto: Oh, it's a really nice accident then. And it really makes sense for our use case. I have multiple instances of an editor, and each editor should have it's own instance of the services they use. So when a particular editor opens some tool connected to that editor in a dialog it should have access to the same instance of the services to access the correct data. Edit: If this is as designed someone can close this. |
Closing, but it can be reopened if something doesn't work out. I also want to note that you have the option of passing in a custom |
@crisbeto: I got this error when I tried to add it to my service: In this case I have a service that handles all dialogs. So I would essentially have to pass the ViewContainerRef from each component using a dialog each time? That's unfortunately a lot of places. |
Injecting a
|
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. |
Which @angular/* package(s) are the source of the bug?
Don't known / other
Is this a regression?
Yes
Description
After upgrading from Angular 13.x.x to 14.x.x my services are no longer injected into components opened/instantiated through MatDialog.
MatDialog
andTestService
is provided inTestComponent
.Opening
DialogComponent
withthis.matDialog.open(DialogComponent)
fromTestComponenent
no longer works.This scenario is currently used by us to make sure components in dialogs get the correct scope based on which component opens the dialog.
I couldn't find any breaking changes in @angular/angular or @angular/material concerning this.
Working example:
https://stackblitz.com/edit/angular-13-provider-works
Not working example:
https://stackblitz.com/edit/angular-14-provider-bug
Please provide a link to a minimal reproduction of the bug
https://stackblitz.com/edit/angular-14-provider-bug
Please provide the exception or error you saw
Please provide the environment you discovered this bug in (run
ng version
)The text was updated successfully, but these errors were encountered: