How to import/use lazy load module on another ng-module

时光怂恿深爱的人放手 提交于 2019-12-12 11:43:02

问题


I have two ng-module

  1. Dash Board
  2. Repeat order list

I had loaded Repeat order through the lazy load.

Now I want to use Repeat order, inside dashboard as html

<app-repeatorderlist></app-repeatorderlist>

If I am doing same it is throwing me an error

'app-repeatorderlist' is not a known element: 1. If 'app-repeatorderlist' is an Angular component, then verify that it is part of this module. 2. If 'app-repeatorderlist' is a Web Component then add 'CUSTOM_ELEMENTS_SCHEMA' to the '@NgModule.schemas' of this component to

And if I am adding it's reference on app.module then it's throwing error

Type RepeatorderlistComponent is part of the declarations of 2 modules: AppModule and repeatorderModule! Please consider moving RepeatorderlistComponent to a higher module that imports AppModule and repeatorderModule. You can also create a new NgModule that exports and includes RepeatorderlistComponent then import that NgModule in AppModule and repeatorderModule. Error: Type RepeatorderlistComponent is part of the declarations of 2 modules: AppModule and repeatorderModule! Please consider moving RepeatorderlistComponent to a higher module that imports AppModule and repeatorderModule. You can also create a new NgModule that exports and includes RepeatorderlistComponent then import that NgModule in AppModule and repeatorderModul

I can understand I have to create a new module(higher) but how can any body guide on same


回答1:


Here is a working example I just made to show you how it is setup.

  • https://github.com/Tenmak/component-communication/tree/shared-component

  1. AppModule imports the MainModule (similar to your DashboardModule).
  2. ReapeatOrder module is lazy-loaded and can be navigated to from the MainModule
  3. Both Modules import a shared module, with shared components.
  4. Both MainModule and ReapeatOrderuse the shared components in their templates.


来源:https://stackoverflow.com/questions/46053937/how-to-import-use-lazy-load-module-on-another-ng-module

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