【问题标题】:Error on importing component from other module从其他模块导入组件时出错
【发布时间】:2018-11-20 08:21:43
【问题描述】:

我正在尝试将“OpenDialogContentComponent”组件从模块 A 导入到模块 B,但出现错误:

'无法确定 C:/Users/jitdagar/Desktop/TDP/pwt-ui-common/src/app/components/open-dialog-content/open-dialog-content 中类 OpenDialogContentComponent 的模块。组件.ts!将 OpenDialogContentComponent 添加到 NgModule 以修复它。'

这个 OpenDialogContentComponent 组件在模块 A 中导出,并且可以在模块 B 中使用它的选择器。但我的要求是使用 import 语句导入组件。

在模块 B 的组件中:

从 '../../../../Module A/src/app/components/open-dialog-content/open-dialog-content.component' 导入 { OpenDialogContentComponent }; em>

【问题讨论】:

  • 你需要在 ModuleB 的导入下添加你的 ModuleA
  • 模块已经添加,这就是为什么我可以在模块 B 中使用模块 A 的组件的选择器。我想通过导入在路由中使用该组件。
  • 模块 A 可以被视为共享模块,组件“OpenDialogContentComponent”是我想在模块 B 路由中使用的共享组件。
  • 对于那些投反对票的人,请澄清问题是否不清楚/无效/的原因。我想我用答案澄清了我的问题。

标签: angular typescript frontend


【解决方案1】:

自动导入正在生成 'OpenDialogContentComponent' 的相对路径。当我用节点模块路径替换它时,它起作用了。

import { OpenDialogContentComponent } from '../../../../ModuleA/src/app/components/open-dialog-content/open-dialog-content.component';

将路径替换为节点模块路径:

import { OpenDialogContentComponent } from '@Module/ModuleA/src/app/components/open-dialog-content/open-dialog-content.component';

【讨论】:

    猜你喜欢
    • 2019-05-19
    • 2019-05-29
    • 2021-09-27
    • 2017-10-05
    • 2019-11-19
    • 1970-01-01
    • 2018-09-14
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多