简体   繁体   English

NullInjectorError:没有 MatDialog 的提供者! 使用带有垫子对话框的防护时显示错误

[英]NullInjectorError: No provider for MatDialog! error showing while using guard with mat dialog

I have an error:我有一个错误:

VM654 vendor.js:29876 ERROR Error: Uncaught (in promise): NullInjectorError: R3InjectorError(AccountsModule)[CreateAccountGuard -> CreateAccountGuard -> CreateAccountGuard -> ModalService -> MatDialog -> MatDialog -> MatDialog]:   NullInjectorError: No provider for MatDialog!

I do not get what is wrong and why I see it.我不明白出了什么问题以及为什么我看到它。

Basically, in CreateAccountGuard (which is in Accounts Module) I use Modal service to open confirmation modal.基本上,在 CreateAccountGuard(位于 Accounts Module 中)中,我使用 Modal 服务打开确认模式。

Confirmation modal component and ModalService are in another module - Modals module.确认模态组件和 ModalService 在另一个模块 - Modals 模块中。 I have added Confirmation modal component to declarations and entryComponents.我已将 Confirmation 模态组件添加到声明和 entryComponents。 MatDialogModule is also added there in imports. MatDialogModule 也在导入中添加。

While running Jasmine test - no issues.在运行 Jasmine 测试时 - 没有问题。 But on the website - I see this error.但是在网站上 - 我看到了这个错误。

Unfortunately, cannot share the code.不幸的是,无法共享代码。 Maybe you have any ideas what to do from here?也许你有任何想法从这里做什么?

The issue was related to the fact that I was adding MatDialog module to the Modals module (My feature one).该问题与我将 MatDialog 模块添加到 Modals 模块(我的功能之一)这一事实有关。

I have added it to imports in the app.module and it worked.我已将其添加到 app.module 中的导入中,并且可以正常工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM