简体   繁体   English

如何在entryComponents中使用模块中的组件另一个模块?

[英]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和导出FirstModalComponentFirstModalModule 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. 确保ModalsModuleSharedModule根据您的使用导出此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.

相关问题 尽管已在我的模块的 entryComponents 选项中声明了我的组件,但 Angular 如何找不到它的组件工厂? - How Angular can not find the component factory for my component despite it has been declared in the entryComponents option of my Module? 如何使用另一个模块中某个模块的功能的输出 - How to use the output from a function of a module in another module 如何使用AngularJS中另一个模块的功能? - How to use functions from another module in AngularJS? 如何在另一个模块中使用服务/模块? - How to use service/module inside of another module? 如何在另一个模块中使用一个模块并在角度8中路由该模块? - how to use a module in another module and route that in angular 8? 如何从组件中的另一个模块测试自定义指令 - How to test a custom directive from another module in a component 如何将另一个模块中的类型用作JSDoc返回/ param类型 - How to use a type from another module as a JSDoc return/param type 如何将React.lazy用于模块的组件? - How to use React.lazy for a component of a module? NodeJS:使用module.exports从另一个模块的功能 - NodeJS: use module.exports in function from another module 不能从另一个模块或领域使用 GraphQLSchema - Cannot use GraphQLSchema from another module or realm
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM