Skip to content

fix(cdk/dialog): use config injector if provided #25277

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

Closed
wants to merge 1 commit into from

Conversation

ldulary
Copy link
Contributor

@ldulary ldulary commented Jul 14, 2022

Cdk Dialog provides a field injector in config object. We would gladly use it to provide an injector issued from our lazy-loaded module.
It is correctly used on line 224 : const userInjector = config.injector ?? config.viewContainerRef?.injector;
But not on line 311.
So I guess it would be better to use the same "user" injector on both lines.

@@ -308,7 +308,7 @@ export class Dialog implements OnDestroy {
dialogRef: DialogRef<R, C>,
dialogContainer: BasePortalOutlet,
): Injector {
const userInjector = config && config.viewContainerRef && config.viewContainerRef.injector;
const userInjector = config.injector ?? config.viewContainerRef?.injector;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This injector is only used to resolve the layout direction of the dialog (ltr vs rtl). I think that we actually want to use the ViewContainerRef here specifically since its tied to a particular location in the app that might have a different direction than the user-provided injector.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This injector is also used for providing. Because I can see that, without this change, the providers inside lazy-loaded modules are failing. And with that change, they are successfully provided.
I can understand that you want to use the injector inside ViewContainerRef. But in this case, it has to be a ViewContainerRef built inside this class and not a config one.
Indeed, in my case, I do not construct manually the ViewContainerRef. So the config.viewContainerRef is undefined.
Moreover, the name of this parameter is userInjector (same as line 224). As a consequence, it seemed logic to me that this parameter could be overrided by user and not be kept for an internal purpose.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, I see what you mean. I think that we should still resolve the Directionality with the ViewContainerRef injector first, but the user injector can take precedence in the Injector.create call below. We'll need a unit test for the change as well.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok. We have replaced the use of config.injector inside Injector.create and added a unit test as requested.

@crisbeto
Copy link
Member

This change was merged in with ea4e203.

@crisbeto crisbeto closed this Jul 27, 2022
@vapkse vapkse deleted the fix_dialog_injector branch July 27, 2022 14:43
@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 Aug 27, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants