组件不是已知元素

时间:2020-08-13 13:05:26

标签: angular

我有一个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组件?

1 个答案:

答案 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 { }