[英]How to use component from module in entryComponents another module?
I have ngx-bootstrap
modal component. 我有ngx-bootstrap
模态组件。 This modal is used inside shared
folder. 此模式用于shared
文件夹中。 I use this FirstModalComponent
in my DashboardModule
like: 我在DashboardModule
使用这个FirstModalComponent
,如:
// 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
]
});
And if I want to make my FirstModalComponent
as module, how I should implement it in my DashboardModule
and define it in entryComponents
? 如果我想将我的FirstModalComponent
作为模块,我应该如何在我的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 { }
Then I import/export this ModalsModule
in SharedModule
and trying to import shared module into DashboardModule
. 然后我在SharedModule
导入/导出此ModalsModule
并尝试将共享模块导入DashboardModule
。
How can I inject my FirstModalComponent
to entryComponents
in Dashboard now? 我现在如何将我的FirstModalComponent
注入FirstModalComponent
中的entryComponents
?
I get an error when I try to import FirstModalComponent
and put to entryComponents
: Component is part of the declaration of 2 modules
. 当我尝试导入FirstModalComponent
并将其放入entryComponents
时,我收到错误: Component is part of the declaration of 2 modules
。
PS I'm not sure that this is a good idea to make it as module.. PS我不确定将它作为模块是个好主意..
You should be declaring the FirstModalComponent
in only one module
. 您应该只在一个module
声明FirstModalComponent
。 It can be part of one module and exported by the same and can be defined as entryComponent
for it's own module. 它可以是一个模块的一部分并由它们导出,并且可以定义为它自己的模块的entryComponent
。
For your case, declare it as 对于您的情况,请将其声明为
entryComponents: [ FirstModalComponent ]
for the FirstModalModule
and export the FirstModalComponent
from FirstModalModule
. 对于FirstModalModule
和导出FirstModalComponent
从FirstModalModule
。 It will work as expected when you import FirstModalModule
inside ModalsModule
or any other module in your application. 当您在ModalsModule
或应用程序中的任何其他模块中导入FirstModalModule
时,它将按预期工作。
Make sure this FirstModalModule
is exported by your ModalsModule
and the SharedModule
depending on your use. 确保ModalsModule
和SharedModule
根据您的使用导出此FirstModalModule
。 if you want to use it by importing SharedModule
into your DashboardModule
, this has to be exported from SharedModule
. 如果要通过将SharedModule
导入DashboardModule
来使用它,则必须从SharedModule
导出。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.