Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the role of Angular core module?

I read an article about organizing folders in Angular and the author uses one called core, in which he creates the core module and insert only services which will be called once.

Currently, I'm working on a project whereupon I adopted the structure recommended by the article. Inside my core folder/module I created a module called api:

\app
  \core
    \api
    ...
  \shared
  ...

My question is: as the api is a module, I was wondering why not remove it from core and put in app folder?

\app
  \api
  \core
  \shared
  ...

Angular itself has core module too (where we import ngModule, Injectable...) and I'd like to know what is its role.

like image 877
Pedro Arantes Avatar asked Mar 03 '18 13:03

Pedro Arantes


People also ask

What is the use of core module in Angular?

The core module usually contains components that are used once in an Angular application, such as a navigation bar, loader, footer, etc. This module should be loaded globally in AppModule .

What is core and shared modules in Angular?

The Core Module is where we want to put our shared singleton services. So the services that we want only one instance of while having them shared among multiple modules should live here. The Angular injector creates a new instance of a service for each lazily loaded module it is provided.

Why do we need Angular modules?

Modules in angular are a great way to share and reuse code across your application. This is an affiliate link. We may receive a commission for purchases made through this link. Shared modules do not only make your app tidier, but can reduce the actual size of an application by far.

What is the difference between a shared module and a core module an Angular application would commonly use?

CoreModule should have only services and be imported only once in the AppModule . SharedModule should have anything but services and be imported in all modules that need the shared stuff (which could also be the AppModule ).


1 Answers

Your CoreModule contains code that will be used to instantiate your app and load some core functionality.

To get more idea on this read Core Module

like image 189
Sajeetharan Avatar answered Oct 13 '22 20:10

Sajeetharan