1

I am creating (actually rewriting ng 5 app) an Angular app and want to keep reusable self contained modules prepared to reuse.

I’d like to do a minimum first step to have separate my.org folder along with an app and put all the modules there each in separate folder with its own some-feature.module.ts file. I already found that I can use .. to keep the modules out of the app. I’d like to know what else I should consider to keep the modules self contained and decoupled from the app and from each other. The modules can contain either components or just a service for a single module.

Making the modules npm-able is not in scope of this step.

ciekawy
  • 2,238
  • 22
  • 35

1 Answers1

2

You could build your code as Angular libraries:

https://angular.io/guide/creating-libraries

https://blog.angularindepth.com/creating-a-library-in-angular-6-87799552e7e5

And regarding this:

The modules can contain either components or just a service for a single module.

As of Angular v6 and the new providedIn syntax, a service no longer needs to "belong" to any module or component. A module only needs to contain components, directives, and pipes.

DeborahK
  • 57,520
  • 12
  • 104
  • 129
  • awesome, will try to follow that path. So as for services - if I want to keep a service separate and singleton I do not even need to declare a module for it? – ciekawy Feb 12 '19 at 13:33
  • It does not need a module, correct. You just need to ensure you use the `providedIn` property of the `Injectable` decorator. – DeborahK Feb 12 '19 at 16:04