I am trying to develop a a simple angular app using NgRx to maintain state.
Unfortunately, the callback to the subscription to the store gets fired but always returns an empty object.
I am trying to dispatch the object to store as
this._store.dispatch({
type: 'ShowPassword',
payload: value
})
and a look at the reducer function
export function showPasswordReducer(state, action) {
//console.log(state);
switch (action.type) {
case 'ShowPassword':
return {
...state,
'ShowPassword': action.payload
}
break;
default:
return state;
}
}
I am adding the reference of StoreModule in the imports array of root module as
StoreModule.forRoot(showPasswordReducer)
and subscribing to the store as
this._store.subscribe(val => {
if (val)
this.showPassword = val.ShowPassword;
})
Stackblitz link: https://stackblitz.com/edit/angular-first-ngrx-demo