2

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):

@NgModule({
    declarations: [MyApp, ModelOnePage, ModelTwoPage ],
    imports: [
        IonicModule.forRoot(MyApp),
        StoreModule.provideStore({ modelOne: ModelOneReducer, modelTwo: ModelTwoReducer }),
        EffectsModule.run(ModelOneEffects),
        EffectsModule.run(ModelTwoEffects),
    ],
    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:

@NgModule({
    declarations: [ ModelOnePage ],
    imports: [
        IonicPageModule.forChield(ModelOnePage),
        StoreModule.provideStore({ modelOne: ModelOneReducer }),
        EffectsModule.run(ModelOneEffects),
    ],
    //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...)

Eduardo
  • 277
  • 1
  • 6
  • 17

1 Answers1

0

Just separate your app.module.ts, import new one to the main.ts and bootstrap it

Also this question may brings you new ideas

Evan Bor
  • 29
  • 1
  • 5
  • Thanks for the insight, I was indeed unaware about the main.ts file, however when I tested I got the following `Error: Uncaught (in promise): Error: No provider for ModelOneService!` – Eduardo Jul 13 '17 at 19:31