【问题标题】:Angular module importing and component usageAngular 模块导入和组件使用
【发布时间】:2020-08-19 22:27:46
【问题描述】:

我有一个如图所示的目录结构

https://i.stack.imgur.com/yitTd.png

当我在 app.component.html 中使用<app-news-card> 选择器时,它显示错误<app-news-card> not present in current module.

我应该如何以最实用的方式解决这个问题。

目前: 我是

1.)从 news.module 导出 news-card.component

2.) 然后我在 current.module 中导入 NewsModule 并重新导出 NewsModule

3.) 然后我在 app.module

中导入了 CurrentModule

【问题讨论】:

标签: angular typescript import module components


【解决方案1】:

确保在 news.module 的声明中包含 news card 组件。例如:

@NgModule({
  declarations: [NewsCardComponent],
  imports: [...],
  exports: [NewsCardComponent]
})

更多关于提升的信息可以在这里找到:Docs

【讨论】:

  • 它在那里,我也导出了。
  • 你能编辑你的答案并包含 news.module、current.module 和 app.module,或者提供一个 stackblitz 什么的吗?
  • 看看这个Stackblitz
猜你喜欢
  • 2017-06-17
  • 2020-07-24
  • 2018-01-24
  • 2017-01-27
  • 1970-01-01
  • 2019-03-22
  • 1970-01-01
  • 2016-10-04
  • 2017-10-01
相关资源
最近更新 更多