我有一个shared
模块中的组件,并且已经在另一个模块中成功使用了该组件,但是,当我尝试在第二个组件中使用该组件时,出现以下错误; < / p>
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
组件?
答案 0 :(得分:0)
发现问题,没有将dashboard
组件导入到app.module.ts
文件中,而是添加了它来解决了问题;
@NgModule({
declarations: [
AppComponent
],
imports: [
BrowserModule,
BrowserAnimationsModule,
AngularFireModule.initializeApp(environment.firebase),
AppRoutingModule,
AccessModule,
DashboardModule,
SharedModule
],
providers: [],
bootstrap: [AppComponent]
})
export class AppModule { }