2
votes

I am working on a sample Angular 2 application , and I am planning to use @ngrx/store and @ngrx/effects for state management.

This sample application has a root module and multiple feature modules.

Now my questions are.

  1. Can I import StoreModule and EffectsModule in all my feature modules OR Should they be imported only once in root module ?

  2. In order to import a single effects file in a module I had written below line of code in module file

    EffectsModule.run(AuthorEffects) 
    

    What if there are multiple effect files ?

2

2 Answers

0
votes

Most of the time it should be imported in the root module. It looks like the ngrx has a solution in the v3 beta version to provide dynamic reducer functionality:

https://github.com/ngrx/store/pull/269

As far as multiple effects, you will need to call EffectsModule.run() for each effect.

0
votes

Very good practice is to import feature modules to root module dynamically. You can use ForFeature for this. Your root store is empty from scratch and this is very good for scale your application.

I recommend you investigate this official sample. It can answer a lot of your questions.

I hope, I helped you.