首页 > 解决方案 > 如何在当前模块中使用其他模块的组件?

问题描述

我有两个模块。我需要在对话框中显示组件。但是该组件在其中导入了几个组件(超过 20 个)。因此,如果有一个组件,我会在公共模块中创建。但这更复杂。我尝试从另一个模块导出组件。但这会给我一个错误,因为它没有在这个模块的入口组件中声明。

@NgModule({
declarations: [
    DocumentEditComponent,
    TestimonialLieuComponent,
    CommNetworkAddDialogComponent,
    GoalComponent,
    InterviewGuideComponent,
    JobCommunicationComponent,
    LearningComponent,
    MatchConfigComponent,
    PayDetailComponent,
    PerksAndBenefitsComponent,
    QuestionnaireComponent,
    VendorComponents,
    WorkRelatedComponent,
    ConfigurationComponent,
    BasicInfoComponent,
    AddDialogComponent,
    JdmDetailAddComponent,
    JdmDetailComponentComponent,
    InterviewGuideMapComponent,
    AdminOrgJdmComponent,
    AdminOrgJdmDetailComponent,
    OrgJdmAddComponent,
    OrgInterviewGuideComponent,
    OrgExperienceComponent,
    OrgCommNetworkComponent,
    OrgWorkRelatedComponent

],
exports: [
  TestimonialTemplateComponent,
  TestimonialComponent,
  AdminOrgJdmDetailComponent
],
imports: [
    CommonModule,
    TapCommonModule,
    RecruitmentConfigRoutingModule
],
entryComponents: [
    PhysicaldemandEditOrgComponent,
    InterviewProcessComponent,
    AssessmentsComponent,
    CareerPathComponent,
    DocumentComponent,
    ExperienceComponent,
    GoalComponent,
    InterviewGuideComponent,
    JobCommunicationComponent,
    LearningComponent,
    MatchConfigComponent,
    PayDetailComponent,
    PerksAndBenefitsComponent,
    QuestionnaireComponent,
    VendorComponents,
    WorkRelatedComponent,
    ConfigurationComponent,
    AddDialogComponent,
    JdmDetailAddComponent,
    InterviewGuideMapComponent,
    OrgJdmAddComponent,
    AssessmentOrgAddComponent,
    CareerPathOrgAddComponent,

],
providers: []
})
export class RecruitmentConfigModule {
}

并在对话框中调用组件

openJD(): void {
let dialogRef = this.dialog.open(AdminOrgJdmDetailComponent, {
  width: '80%',
  data: this.jobDescription,
  height: '90%',
  disableClose: true
});
dialogRef.afterClosed().subscribe(result => {

});

}

这给我一个错误

VM60232 JobRequisitionAddFormComponent.ngfactory.js:230 错误 错误:找不到 AdminOrgJdmDetailComponent 的组件工厂。你把它添加到@NgModule.entryComponents 了吗?

任何其他方法来解决这个问题。请告诉我

标签: angular

解决方案


我会尝试将 AdminOrgJdmDetailComponent 添加到 entryComponents 数组中。正如错误所说,在那里找不到它。由于您以动态方式加载它,我认为您必须告诉 Angular 强制加载它。

...
entryComponents: [
    ...
    AdminOrgJdmDetailComponent 
],
...

你可以在这里找到更多信息。


推荐阅读