Iho*_*hyk 5 javascript angular ngx-bootstrap-modal
我有ngx-bootstrap模态组件。此模式在shared文件夹内使用。FirstModalComponent我DashboardModule喜欢用这个:
// Dashboard.module.ts
import { FirstModalComponent } from '../../shared/modals/first-modal/first-modal.component';
@NgModule({
declarations: [
DashboardComponent
],
imports: [
CommonModule,
ReactiveFormsModule,
RouterModule.forChild(routes),
SharedModule
],
entryComponents: [
FirstModalComponent
]
});
Run Code Online (Sandbox Code Playgroud)
如果我想制作我的FirstModalComponentas 模块,我应该如何在 my 中实现它并在中DashboardModule定义它entryComponents?
import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
import { FirstModalModule } from './first-modal/first-modal.module';
@NgModule({
declarations: [],
imports: [
CommonModule,
FirstModalModule
],
exports: [
CommonModule,
FirstModalModule
]
})
export class ModalsModule { }
Run Code Online (Sandbox Code Playgroud)
然后我导入/导出这个ModalsModule在SharedModule和尝试导入共享模块插入DashboardModule。
我现在如何将我的FirstModalComponentto注入entryComponents仪表板?
当我尝试导入FirstModalComponent并放入entryComponents:时出现错误Component is part of the declaration of 2 modules。
PS我不确定将其作为模块是否是个好主意..
FirstModalComponent您应该在 only one 中声明module。它可以是一个模块的一部分并由同一模块导出,并且可以定义为entryComponent它自己的模块。
对于您的情况,将其声明为
entryComponents: [
FirstModalComponent
]
为FirstModalModule并导出FirstModalComponent来自FirstModalModule。当您导入应用程序中的FirstModalModule内部或任何其他模块时,它将按预期工作。ModalsModule
确保这FirstModalModule是由您导出的ModalsModule,并且SharedModule取决于您的用途。如果您想通过导入SharedModule到您的 中来使用它DashboardModule,则必须从 中导出它SharedModule。