4

I have my own applicaton, written in Angular2, consist of several modules. To keep order in code, I found that I should isolate all services (for communication with API) to separate module.

I wonder if it's good idea? Can it have an impact on loading time or size my app? Could this be other negative effects? If so, why? And what are the best practices to dividing application on modules.

Thanks.

4

2 回答 2

4

您的服务应存储在使用它们的同一模块中。

如果在多个模块中重用它,您可能希望将它们放在主组件中,该组件通常也会存储其模型。

于 2017-01-12T14:05:00.270 回答
1

将服务存储在同一个模块中是一种很好的做法,但有时,不同的模块使用一些服务,因此 CoreModule 是存储它们的最佳方式。

来自 angular 2 styleguide, STYLE 04-11

一定要在CoreModule 中放置一个其实例将在整个应用程序中共享的单例服务(例如ExceptionService 和LoggerService)。

在所有建议之后,有一个树形视图和 Angular 应用程序示例,其中实现了 CoreModule(wich 存储服务)。

于 2017-01-12T15:35:08.243 回答