首页 > 解决方案 > 如何在构造函数中选择性地注入 MAT_DIALOG_DATA

问题描述

我创建了一个名为 customer-edit.component.ts 的组件。有一个页面可以访问客户编辑页面。但是,在其他屏幕中,我希望编辑客户但没有到客户页面的路线。所以我通过使用 mat 对话框来使用弹出窗口来实现这一点。弹出窗口没问题,但是当我尝试通过客户维护屏幕而不是弹出窗口访问屏幕时,我点击了这个

StaticInjectorError(AppModule)[CustomerEditComponent -> InjectionToken MatDialogData]: StaticInjectorError(Platform: core)[CustomerEditComponent -> InjectionToken MatDialogData]: NullInjectorError: No provider for InjectionToken MatDialogData!

如何@Inject(MAT_DIALOG_DATA) public data: any根据我访问屏幕行为的方式来选择性地将 in 构造函数注入 customer-edit.component.ts 以防止出现此错误?

标签: angulartypescript

解决方案


我还需要添加MatDialogRef组件提供程序。此答案中提供了示例。


推荐阅读