State未与localStorage

时间:2018-02-15 17:01:19

标签: javascript angular local-storage ngrx ngrx-store

我使用ngrx-store-localstorage包来同步localstorage和ngrx/store之间的状态。我把它设置为像在Github上展示的那样,但它不起作用。我轻松登录,ngrx devtools中的状态已更新,但localstorage中的标记在设置初始状态时仍为空。

这是包,代码和所有内容的github链接: https://github.com/btroncone/ngrx-store-localstorage

这是我的代码:



export function localStorageSyncReducer(auth: ActionReducer<any>): ActionReducer<any> {
  return localStorageSync({ keys: ['token'], rehydrate: true })(auth);
}
const metaReducers: Array<MetaReducer<any, any>> = [localStorageSyncReducer];
&#13;
&#13;
&#13;

这也是设定..

StoreModule.forRoot(reducers, { metaReducers })

我还尝试在最后的括号中添加reducers.auth,然后它可以正常工作,但只有&#39;令牌&#39;整个申请状态的财产。

1 个答案:

答案 0 :(得分:0)

我会尝试将其放入我的代码中:

export const getAuthState = createFeatureSelector<State.auth>('auth')

然后将参数更改为:

{ keys: ['auth'], rehydrate: true }

这适用于整个州。