-
Notifications
You must be signed in to change notification settings - Fork 6.8k
Closed
Labels
Description
Reproduction
When using MatDialog in a dynamically loaded component it doesn't work and throws error No provider for MatDialog
.
Steps to reproduce:
- Follow the instructions in this post (https://medium.com/angular-in-depth/lazy-load-components-in-angular-596357ab05d8 ) to create a dynamically loaded component
- Add
MatDialogModule
to the imports array ofNGModule
for the dynamically loaded component. ng serve
and check the error in console.
Expected Behavior
It should work without throwing any error.
Actual Behavior
Throws below error:
zone-evergreen.js:659 Unhandled Promise rejection: R3InjectorError(AppBrowserModule)[MatDialog -> MatDialog -> MatDialog]:
NullInjectorError: No provider for MatDialog! ; Zone: <root> ; Task: Promise.then ; Value: NullInjectorError: R3InjectorError(AppBrowserModule)[MatDialog -> MatDialog -> MatDialog]:
NullInjectorError: No provider for MatDialog!
at NullInjector.get (http://localhost:4200/vendor.js:34269:27)
at R3Injector.get (http://localhost:4200/vendor.js:48199:33)
at R3Injector.get (http://localhost:4200/vendor.js:48199:33)
at R3Injector.get (http://localhost:4200/vendor.js:48199:33)
at NgModuleRef$1.get (http://localhost:4200/vendor.js:65751:33)
at Object.get (http://localhost:4200/vendor.js:63486:35)
at getOrCreateInjectable (http://localhost:4200/vendor.js:38115:39)
at Module.ɵɵdirectiveInject (http://localhost:4200/vendor.js:52134:12)
at NodeInjectorFactory.MyDynamicallyLoadedComponent_Factory [as factory]
Environment
- Angular: 10.0.0-next.6 (same behavior in other versions e.g. 9.x)
- CDK/Material: 9.2.3
- Browser(s): Chrome
- Operating System (e.g. Windows, macOS, Ubuntu): Windows
PierreDuc, Splaktar and mrfoster