Tl;dr: It seems the core.module
style is no longer part of the official Angular Style Guide, but it must have been removed only recently. What is the new best practice for importing singleton services and why was the style removed?
I just read this guide on getting started with Angular Material and it states
Then (as per the Angular Style Guide) I created a Core module
I checked the Style Guide, but can't seem to find the guideline referenced here. During my search I stumbled over the following sources:
A blogpost from Nov. '18 explaining the difference between core.module and shared.module.
This question from Oct. '17 with a very detailed explanation of the core.module.
This question from Jul. '18, which went unnoticed.
The last Question refers to the core.module
style with this link:
https://angular.io/guide/styleguide#core-feature-module
It seems the #core-feature-module
anchor has been removed and is no longer part of the official Angular style guide. Only the shared feature module guideline remains.
Why was the core.module
guideline removed? What is the new best practice for importing singletons such as services?
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 ).
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 .
Angular Style Guide: A starting point for Angular development teams to provide consistency through good practices.
An AngularJS module defines an application. The module is a container for the different parts of an application. The module is a container for the application controllers. Controllers always belong to a module.
Well, simply said it never been required:
You may also completely remove the following files. They are AngularJS module configuration files and not needed in Angular:
- app/app.module.ajs.ts
- app/app.config.ts
- app/core/core.module.ts
- app/core/phone/phone.module.ts
- app/phone-detail/phone-detail.module.ts
- app/phone-list/phone-list.module.ts
As for the reason why it got removed:
@jenniferfell @brandonroberts fyi. @jenniferfell we removed
CoreModule
as a recommended technique because now the preferred way of providing services is usingprovidedIn
, however @bisonfoutu has a great point. I think the focus of this issue might be best suited for a style guide point on Feature Modules orSharedModule
section, but I'd love to hear what the team and community have to say.IMO, where it could go were we to come to the conclusion that we should advise this technique: https://angular.io/guide/styleguide#shared-feature-module
Thanks for filing this issue, @bisonfoutu!!
Thoughts are welcome! ✨
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With