Posts

Showing posts from March, 2017

Angular (2+): Core vs Shared Modules

Angular: Core vs Shared Modules If you're new to Angular, you might get confused between these two commonly used modules. So what do you put in either components?  What goes in CoreModule? Your CoreModule contains code that will be used to instantiate your app and load some core functionality.  The clearest and most important use of the CoreModule is the place to put your global/HTTP services. The idea is to make sure only one instance of those services will be created across the entire app. The CoreModule, by convention, is only included in your entire app once in AppModule (only in the "import" property of the "@NgModule()" decorator inside your main app.module.ts, not in any other module's "import") and this will ensure services inside it will be only created once in the entire app. This is especially important if you intend to lazy-load your feature modules. Since lazy-loaded modules are loaded on demand (eg when you access the rou