7

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?

codepearlex
  • 544
  • 4
  • 20

1 Answers1

1

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! ✨

Shinjo
  • 677
  • 6
  • 22
  • I understand the file is listed as an unneeded configuration file in the [Upgrading from AngularJS](https://angular.io/guide/upgrade#say-goodbye-to-angularjs) guide and frankly I don't understand why. However, there are countless sources from the past years referring to the `core.module` style in the context of Angular ^2, and it seems until recently it was still part of the official style guide. My question remains. – codepearlex Aug 22 '19 at 09:56
  • @codepearlex reasonable enough. I added a citation from the git response about it. – Shinjo Aug 22 '19 at 10:01
  • This is exactly what I was looking for! The `providedIn` option of the `@Injectable()` decorator renders the `core.module` style useless, because it was intended for singleton imports only. However, the blog post in which I originally read about the `core.module` recommended importing Angular Material there. It seems this is was bad advice, even back when the `core.module` was still considered best practice, because Angular Material is not a service, but a collection of components. – codepearlex Aug 22 '19 at 12:21
  • 1
    BTW: The new best practice is described in the [Providing a service](https://angular.io/guide/styleguide#providing-a-service) style in the current [Style Guide](https://angular.io/guide/styleguide). Thanks for shedding some light on this. – codepearlex Aug 22 '19 at 12:22