Reputation: 5374
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.
Upvotes: 4
Views: 430
Reputation: 1888
Storing services in the same modules is a good practice, but sometimes, there are services that are used by different modules, so CoreModule is the best way for storing them.
From angular 2 styleguide, STYLE 04-11:
Do put a singleton service whose instance wil be shared throughout the application in the CoreModule (e.g. ExceptionService and LoggerService).
After all recommendations, there's a tree view and example of angular app with CoreModule (wich stores services) implemented.
Upvotes: 1
Reputation: 32767
Your services should be stored in the same module that is using them.
In case of reusing it in several modules, you might want to have them in the main component, the one which will generally store its model as well.
Upvotes: 4