简体   繁体   English

Angular 模块 - 通过延迟加载重用来自域模块的共享组件的最佳实践

[英]Angular modules - best practises of reusing shared components from domain modules with lazy loading

I know the concepts of lazy loading and sharing modules, but I'm not sure what will be the best practice of deviding code into modules in my app.我知道延迟加载和共享模块的概念,但我不确定在我的应用程序中将代码划分为模块的最佳实践是什么。 I have 4 pages:我有 4 页:

  1. Dashboard仪表板
  2. Drinks饮料
  3. Drinks recipes饮品食谱
  4. Bars酒吧

So I divided my app into 4 logical, domain modules: DashboardModule , DrinksModule , RecipesModule , BarsModule .因此,我将我的应用程序分为 4 个逻辑域模块: DashboardModuleDrinksModuleRecipesModuleBarsModule While coding I've noticed that I have some dependencies between modules:在编码时,我注意到模块之间存在一些依赖关系:

  1. DashboardModule reuses some components from all other modules. DashboardModule重用了所有其他模块中的一些组件。
  2. BarsModule and RecipesModule reuse some components from DrinksModule BarsModuleRecipesModule重用了DrinksModule中的一些组件

So problems I see are:所以我看到的问题是:

  1. With DashboardModule all other modules must be loaded, but only some components are used.使用DashboardModule必须加载所有其他模块,但只使用一些组件。
  2. DrinksModule is always loaded, but only some components are used in other modules. DrinksModule总是被加载,但在其他模块中只使用了一些组件。

I don't want to move all of that reused components to a single SharedModule because these components fit the specific domain (like bar or drinks) and also some components will be loaded unnecessarily.我不想将所有重用的组件移动到单个SharedModule中,因为这些组件适合特定的域(如酒吧或饮料),而且某些组件将被不必要地加载。

Is it sense to split these domain modules like DrinksModule and SharedDrinksModule and what will be the best project structure for that?拆分这些域模块(如DrinksModuleSharedDrinksModule是否有意义,最好的项目结构是什么? Or maybe there is a better practice to handle these problems?或者也许有更好的做法来处理这些问题?

Best option is to create a sharedModule and move the resuble components to that module.最好的选择是创建一个 sharedModule 并将 resuble 组件移动到该模块。 Also make sure to mske those component as dump component.还要确保将这些组件作为转储组件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM