What is the difference between StoreModule.forRoot() and StoreModule.forFeature()

Shanmugam M picture Shanmugam M · Sep 21, 2017 · Viewed 28k times · Source

Recently ngrx store changed the way to register the store variables in an angular application.

What is the difference between StoreModule.forRoot() and StoreModule.forFeature()

Do we need to register both to make the application work?

Answer

dee zg picture dee zg · Sep 21, 2017

Its used with lazy loaded reducers. When you have (lazy loaded) feature modules and you want to register reducers within that module, then you use forFeature. Otherwise, in your AppModule you use forRoot.