How to separate app.module into smaller files?


November 2018


275 time


I'm learning Ionic 3, Angular 4 and ngrx design pattern.

I have a working application but with my app.module.ts looking like this (omitting the imports):

    declarations: [MyApp, ModelOnePage, ModelTwoPage ],
    imports: [
        StoreModule.provideStore({ modelOne: ModelOneReducer, modelTwo: ModelTwoReducer }),,,
    bootstrap [IonicApp],
    entryComponents: [MyApp, ModelOnePage, ModelTwoPage ],
    providers: [ModelOneActions, ModelOneService, 
                ModelTwoActions, ModelTwoService, 'andSomeIonicStuff']
export class AppModule { }

However I would like to have separate .module files such as a modelOne.module.ts:

    declarations: [ ModelOnePage ],
    imports: [
        StoreModule.provideStore({ modelOne: ModelOneReducer }),,
    //bootstrap [?],
    entryComponents: [ ModelOnePage ],
    providers: [ModelOneActions, ModelOneService ]
export class ModelOneModule { }

And so on, with each model/page having its own.

I'm asking because having a gigantic file with everything is clearly horrible for structure. Also managing git conflicts and merges when multiple people are working in the same project doing different parts and having to modify the same file is not ideal.

So far I got this working for the pages bit, implementing the lazy loading strategy, but the imports for StoreModule and EffectsModule and the providers do not work.

I'd like to know if there is a way to achieve what I'm trying to do. If there is not, then why is it? Which part of the stack is at fault? (ngrx-plugin, angular4, ionic3...)

1 answers


Просто отделить app.module.ts, импортировать новый в main.ts и инициализировать ее

Кроме того, этот вопрос может приносит вам новые идеи