Node Promiscuous Modules

    ng2-module-decorator
    TypeScript icon, indicating that this package has built-in type declarations

    1.0.5 • Public • Published

    ng2-module-decorator

    Avoid the Angular 2 module declaration hell by providing a simple decorator.

    Install

    npm install ng2-module-decorator --save

    Usage

    First you have to apply the decorator on your class

    import { Component, OnInit } from '@angular/core';
    import { Module } from 'ng2-module-decorator';
     
    @Module('mymodule')
    @Component({
        selector: 'app',
        templateUrl: 'app.html'
    })
    export class AppComponent implements OnInit {
        constructor() { }
     
        ngOnInit() {
     
        }
    }
     

    Then in your module.ts file :

    import { declarations } from 'ng2-module-decorator';
    // import all the app components
    import './components';
     
    // import all the app pipes
    import './pipes';
     
    // import all the app directives
    import './directives';
     
    import { AppComponent } from './components';
     
    @NgModule({
        providers: [
     
        ],
        imports: [
            BrowserModule
        ],
        declarations: [
            ...declarations['mymodule']
        ],
        bootstrap: [ AppComponent ]
    })
    export class AppModule { }

    That's it ! All your classes will be available in the declarations dictionnary. Don't forget to import your require classes in your module file.

    If you are using Webpack and, like me you are lazy, you can import a folder using require.context instead of imports all your files manually.

    Install

    npm i ng2-module-decorator

    DownloadsWeekly Downloads

    14

    Version

    1.0.5

    License

    ISC

    Last publish

    Collaborators

    • shabs