angular - 组件不是已知元素
问题描述
我有一个位于模块中的shared
组件,并且我在另一个组件中成功使用了该组件,但是,当我尝试在第二个组件中使用它时,我看到以下错误;
ERROR in src/app/dashboard/dashboard-report/dashboard-report.component.html:1:1 - error NG8001: 'app-header-unauthenticated' is not a known element:
1. If 'app-header-unauthenticated' is an Angular component, then verify that it is part of this module.
2. If 'app-header-unauthenticated' is a Web Component then add 'CUSTOM_ELEMENTS_SCHEMA' to the '@NgModule.schemas' of this component to suppress this message.
我已经查看了我所做的事情,但我看不出我哪里出错了。
我有一个名为的模块shared
,它有一个名为的组件header-unauthenticated
,它被导出,因此它可以在其他模块/组件中使用。这是shared
模块;
@NgModule({
declarations: [
AlertComponent,
HeaderUnauthenticatedComponent
],
exports: [
AlertComponent,
HeaderUnauthenticatedComponent
],
imports: [
CommonModule
]
})
export class SharedModule { }
我正在尝试在另一个模块header-unauthenticated
内的一个名为的组件内使用该组件。我已经将模块导入到模块中,以便可以使用它的组件,但它们似乎不起作用。这是模块;dashboard-report
dashboard
shared
dashboard
dashboard
@NgModule({
declarations: [DashboardReportComponent],
imports: [
CommonModule,
SharedModule
]
})
export class DashboardModule { }
我里面有另一个模块access
和一个组件login
,我可以header-unauthenticated
毫无问题地使用该组件,并且将access
模块与dashboard
模块进行比较,我看不出任何差异。
@NgModule({
declarations: [LoginComponent],
imports: [
CommonModule,
SharedModule,
ReactiveFormsModule
]
})
export class AccessModule { }
我哪里出错了,为什么header-unauthenticated
找不到组件?
解决方案
发现问题,dashboard
组件没有被导入app.module.ts
文件,添加解决了问题;
@NgModule({
declarations: [
AppComponent
],
imports: [
BrowserModule,
BrowserAnimationsModule,
AngularFireModule.initializeApp(environment.firebase),
AppRoutingModule,
AccessModule,
DashboardModule,
SharedModule
],
providers: [],
bootstrap: [AppComponent]
})
export class AppModule { }
推荐阅读
- python - 如何在pyspark中分组后从列中取出唯一值并创建具有某些条件的另一列
- r - r-exams 关于 2 个不同 xxx.Rmd 文件的相同数据的问题
- angular - this.x.toLowerCase 不是函数 - 过滤器的问题 angular ionic
- postgresql - TypeORM 未将 NULL 设置为 DateString
- python - 使用 Python 将产品聚类为产品系列
- python - 熊猫将行融为一列
- teradata - 通过 querygrid 从 hive 中获取列名
- swagger - 使用 minItems 和 maxLength 为项目生成 Swagger 代码
- scala - http4s - 如何创建线程数有限的 blaze 客户端?
- javascript - 如果我在 package.json 中设置“类型:模块”,Cordova 构建会失败。我该如何解决这个问题,但仍然进行单元测试?