angularangular2-modules

How can I create an Angular 7 app being prepared to extract reusable ng modules?


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.


Solution

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