angular - 如何在构造函数中选择性地注入 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 以防止出现此错误?
解决方案
我还需要添加MatDialogRef
组件提供程序。此答案中提供了示例。
推荐阅读
- css - 带有css的响应式lightroom风格网格?
- vb.net - 第二次显示后未调用表单显示
- python - 我在梯度下降中遇到问题,它给我的 thetas 没有
- android - 如何平滑离散数据点以使其看起来连续?
- redis - Redis位图split key分割策略
- html - 部署 react/express 应用程序后出现内容安全策略错误
- php - 是否可以在 PHP 中放置两个表单并保存两个 cookie 值?
- r - 运行 spdep::lagsarlm(空间自回归模型)后如何解决“impacts()”邻居长度错误?
- amazon-web-services - AWS RDS 数据 API 执行语句不返回列名
- python - Django,bycrypt检查密码返回false