Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Angular: What happened to the core.module style?

Tags:

angular

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?

like image 373
codepearlex Avatar asked Aug 22 '19 09:08

codepearlex


People also ask

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 ).

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 Angular style guide?

Angular Style Guide: A starting point for Angular development teams to provide consistency through good practices.

What is the module in Angular?

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.


1 Answers

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 using providedIn, 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 or SharedModule 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! ✨

like image 147
Shinjo Avatar answered Oct 17 '22 19:10

Shinjo