-
Notifications
You must be signed in to change notification settings - Fork 311
Dispatching an action in constructor of root component doesn't fire #207
Comments
From your description, your reducers are being registered after the app component is instantiated. This is different from what I experience, my reducers are in feature modules, which are imported in the main module, so they are provided to the store before the main component is instantiated and bootstraped. If you haven't upgraded to angular rc6, I suggest you to keep the workaround until you're able to migrate to latest angular/ngrx versions. |
Thanks for the suggestion but this isn't the case. I am on rc.6 already. @ngrx modules are all imported in my app module and my app component is set as the bootstrap component. I am using @ngrx/store, @ngrx/effects, @ngrx/router-store, @ngrx/store-devtools and @ngrx/store-log-monitor. My store is initialised in my app module with StoreModule.provideStore(reducer). The 'reducer' is a compose(combineReducers)({...}) call where by reducers are set up. Other calls are working in the rest of the app apart from this one in the constructor or my root component. Any other ideas? Thanks, Simon |
Are you still experiencing this issue? |
Hi, Yes, I am still seeing this issue. If I dispatch an action in my app constructor it does not hit my reducer or show up in the ngrx dev tools. I am using this to pre-load some data so the reducer sets a loading flag and I have an effect which makes an http call. Interestingly the effect does pick up the action and my data is loaded. In my app I have changed my effect to use startWith after I saw it in one of your samples which is a nicer approach but this does seem like a bug to me. Thanks, Simon |
Please check this against NgRx v4, and if it’s still an issue, please reopen on https://github.com/ngrx/platform. Thanks! |
Hi,
In my root app component I have the following in my constructor but my reducer function is never hit.
this.store.dispatch(this.dataActions.doStuff(args));
Moving the same code to a 'page level' routed component works fine as does wrapping the above in a setTimeout like this...
setTimeout(() => {
this.store.dispatch(this.dataActions.doStuff(args));
}, 0);
Thanks, Simon
The text was updated successfully, but these errors were encountered: