question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

MatDialog: When using in dynamically loaded component workaround deprecated

See original GitHub issue

What 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

  1. Add the MatDialogModule to the root module so that the service is available in your whole application
  2. 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:

  1. https://stackblitz.com/edit/components-issue-m7dysp?file=src/main.ts
  2. Notice all the deprecations image

Environment

  • Angular: 13.3.0
  • CDK/Material: 13.3.0

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:9 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
devversioncommented, May 23, 2022

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

0reactions
angular-automatic-lock-bot[bot]commented, Jun 23, 2022

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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Dynamically load a component inside a Material MatDialog
What I would like to do is this: I will provide the MatDialog configuration data with a component Type which the dialog would...
Read more >
Building Angular 2 Components on the Fly: Dialog Boxes
There's no recipe for building dynamic Angular 2 components on the fly, but that doesn't mean it can't be done. Here's our solution....
Read more >
Angular Dynamic Component in Material Dialog - ngconf
Something has to subscribe to the Observable to cause the lazy load to happen. We do this with the async pipe in the...
Read more >
Inject dynamic content in Angular components with portals
Learn how to dynamically render content in your Angular components using Angular CDK portals in this in-depth tutorial.
Read more >
Angular 10 - Avoid using ::ng-deep (ngdeep)
We prefer all styling in the StyeSheet of the component. Old Solution Was If we ignore the ::ng-deep deprecation warning for now, (after...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found