Angular NGXS存储插件在本地和;会话存储

Angular NGXS存储插件在本地和;会话存储,angular,local-storage,session-storage,ngxs,Angular,Local Storage,Session Storage,Ngxs,我正在使用带有@NGXS/storage插件的NGXS。当我在模块中导入插件时,我可以通过storage选项将插件配置为使用localStorage或sessionStorage 当用户在登录时选中“记住我”选项时,我的应用程序应使用localStorage;当用户不使用“记住我”选项时,应使用sessionStorage 你知道我如何使用@ngxs/storage插件实现这一点吗 @NgModule({ imports: [ CommonModule,

我正在使用带有
@NGXS/storage插件的NGXS。当我在模块中导入插件时,我可以通过
storage
选项将插件配置为使用
localStorage
sessionStorage

当用户在登录时选中“记住我”选项时,我的应用程序应使用
localStorage
;当用户不使用“记住我”选项时,应使用
sessionStorage

你知道我如何使用
@ngxs/storage插件实现这一点吗

@NgModule({
    imports: [
        CommonModule,
        NgxsModule.forRoot(STATES_MODULES, OPTIONS_CONFIG),
        NgxsStoragePluginModule.forRoot({storage: '????'}),
        NgxsReduxDevtoolsPluginModule.forRoot(DEVTOOLS_REDUX_CONFIG),
        NgxsLoggerPluginModule.forRoot(LOGGER_CONFIG)
    ],
    exports: [NgxsModule]
})
export class NgxsStoreModule {}


我将使用自定义存储引擎:

如果您可以控制存储引擎,那么这可能会起作用。不确定是否可以使用angular的DI注入存储/其他内容,以确定用户是否正在尝试设置“rememberMe”

export class MyStorageEngine implements StorageEngine {
  ....

  setItem(key: string, val: any): void {
    if (rememberMe) {
      // set with localStorage
    } else {
      // set with sessionStorage
    }
  }
  ....
}

您不能在运行时更改插件选项。您必须编写自己的插件。