Many Modules using the same component causes error - Angular 2

梦想与她 提交于 2019-12-02 22:38:52
Paul Samsotha

Yes, components can be declared only in one module, and nor are their access inherited in any way, meaning declaring it in the main app module will not give you access to it in any other module.

If you have a component that is used by other modules, generally they way to go is to put it in a shared module

Include component in a shared module:

@NgModule({
  declarations: [ SharedComponent ],
  exports: [ SharedComponent ]
})
class SharedModule {}

How to use the shared module elsewhere:

@NgModule({
  imports: [ SharedModule ]
})
class ModuleWithComponentThatUsesSharedComponent {}

See Also

If you want to use the GoComponent across multiple modules, you should be created a "shared" module and add the GoComponent to the shared module's exports. Then you import shared module into your other modules where you want to use this component.

Find out more information at here

Hope this help!

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!