首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何订阅NgRx中功能模块的更改?

如何订阅NgRx中功能模块的更改?
EN

Stack Overflow用户
提问于 2018-03-08 03:57:13
回答 1查看 987关注 0票数 1

我用的是AoTand lazy-loading。我也在尝试懒洋洋地加载我的存储模块。我的问题是,当我订阅功能模块时,我会得到“未定义的”,而不是使用Redux工具获取存储数据,我可以看到,这个特性是延迟加载的,并且正确地填充了数据。

这是我的appState减速器,

代码语言:javascript
复制
export interface AppState {
  auth: fromAuth.State;
  httpAction: fromHttpActions.State;
  Geo: fromGeoActions.State;
  UI: fromUI.State;
  DbSearch: fromDbSearch.State;
  LocationSearch: fromlocationSearchReducer.State;
  AppDropdownList: fromdropdownReducer.State;
}

export const reducers: ActionReducerMap<AppState> = {
  auth: authReducer,
  httpAction: httpActionReducer,
  Geo: geoReducer,
  UI: userInterfaceReducer,
  DbSearch: dbSearchReducer,
  LocationSearch: locationSearchReducer,
  AppDropdownList: dropdownReducer
};

我把它注入我的主要应用程序模块如下,

代码语言:javascript
复制
StoreModule.forRoot(reducers),

上面的模块工作得很好,

问题在以下几个方面

代码语言:javascript
复制
export interface IRegistryState {
  patientRegistration: frompatientRegistrationReducer.State;
}
export const registryReducers: ActionReducerMap<IRegistryState> = {
  patientRegistration: patientRegistrationReducer
};

我把它注入功能模块如下,

代码语言:javascript
复制
StoreModule.forFeature('registryStore', registryReducers),

当我执行以下操作时,返回的值总是未定义

代码语言:javascript
复制
  this.registryStore.select(s => s.patientRegistration).subscribe(data => {
      console.log(data);
    });

我在这里做错什么了?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2018-03-08 07:03:39

通过将createFeatureSelector添加到我的AppState模块const getRegistryState来解决问题。因此,在创建了功能存储模块之后,我需要在我的AppStore模块中添加以下魅力,

代码语言:javascript
复制
export interface AppState {
  auth: fromAuth.State;
  httpAction: fromHttpActions.State;
  Geo: fromGeoActions.State;
  UI: fromUI.State;
  DbSearch: fromDbSearch.State;
  LocationSearch: fromlocationSearchReducer.State;
  AppDropdownList: fromdropdownReducer.State;
}

export const reducers: ActionReducerMap<AppState> = {
  auth: authReducer,
  httpAction: httpActionReducer,
  Geo: geoReducer,
  UI: userInterfaceReducer,
  DbSearch: dbSearchReducer,
  LocationSearch: locationSearchReducer,
  AppDropdownList: dropdownReducer
};
export const getRegistryState = createFeatureSelector<IRegistryState>(
  'registryStore'
);

并且在组件中仍然调用AppState存储,然后选择如下特性选择器,

代码语言:javascript
复制
this.appStore
          .select(fromApp.getRegistryState)
          .map(data => data.patientRegistration)
          .subscribe(data => {
            if (data.loaded) {
              this.patientRestration.patchValue(data.patientData);
              console.log(data.patientData);
            }
          });
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/49165162

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档