首页 > 解决方案 > Angular 模块导入和组件使用

问题描述

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

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

标签: angulartypescriptimportmodulecomponents

解决方案


确保news card您的news.module. 例如:

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

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


推荐阅读