我用的是AoT,and lazy-loading。我也在尝试懒洋洋地加载我的存储模块。我的问题是,当我订阅功能模块时,我会得到“未定义的”,而不是使用Redux工具获取存储数据,我可以看到,这个特性是延迟加载的,并且正确地填充了数据。
这是我的appState减速器,
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
};我把它注入我的主要应用程序模块如下,
StoreModule.forRoot(reducers),上面的模块工作得很好,
问题在以下几个方面
export interface IRegistryState {
patientRegistration: frompatientRegistrationReducer.State;
}
export const registryReducers: ActionReducerMap<IRegistryState> = {
patientRegistration: patientRegistrationReducer
};我把它注入功能模块如下,
StoreModule.forFeature('registryStore', registryReducers),当我执行以下操作时,返回的值总是未定义
this.registryStore.select(s => s.patientRegistration).subscribe(data => {
console.log(data);
});我在这里做错什么了?

发布于 2018-03-08 07:03:39
通过将createFeatureSelector添加到我的AppState模块const getRegistryState来解决问题。因此,在创建了功能存储模块之后,我需要在我的AppStore模块中添加以下魅力,
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存储,然后选择如下特性选择器,
this.appStore
.select(fromApp.getRegistryState)
.map(data => data.patientRegistration)
.subscribe(data => {
if (data.loaded) {
this.patientRestration.patchValue(data.patientData);
console.log(data.patientData);
}
});https://stackoverflow.com/questions/49165162
复制相似问题