MatDialog: When using in dynamically loaded component workaround deprecated
See original GitHub issueWhat are you trying to do?
Main issue that has the bug explanation and 2 workarounds provided: MatDialog: When using in dynamically loaded component throws error No provider for MatDialog
- Add the
MatDialogModule
to the root module so that the service is available in your whole application- Retrieve the
ComponentFactoryResolver
for the lazy module and instantiate the component through that.
What troubleshooting steps have you tried?
Out of the two workarounds the first one is going against minifying the initial bundle size and the lazy loading principles in case the material component is used only in the lazy module.
The second @devversion’s workaround functions well, however, now that both ComponentFactoryResolver
and Compiler
usage is deprecated with Ivy it is something that needs either another workaround or a proper fix.
Possibly related issue(https://github.com/angular/components/issues/10820) which I have encountered as well, the dynamically loaded components with angular material dependency resolution is in underwhelming state which limits their usage for complex angular applications.
Reproduction
Steps to reproduce:
- https://stackblitz.com/edit/components-issue-m7dysp?file=src/main.ts
- Notice all the deprecations
Environment
- Angular: 13.3.0
- CDK/Material: 13.3.0
Issue Analytics
- State:
- Created a year ago
- Comments:9 (3 by maintainers)
Top GitHub Comments
Thanks for posting this here. Yes, I can confirm that this is the expected API (it has been introduced in v13): https://github.com/angular/components/blob/c67a299a38b713c660b571b9f004168e2a9155db/src/components-examples/private/load-example.ts#L21
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.