ngrx存储选择器给出“未定义地图”错误

时间:2018-07-10 13:57:09

标签: angular rxjs ngrx

当我为具有特定区域ID的区域选择商店时,正确加载了“区域”的商店状态,我得到了错误:

core.js:1542错误ReferenceError:未定义地图     在SafeSubscriber.selectedRegion $ .subscribe.region中(作为_next)(在push ../ src / app / pages / milestones / management / milestone.component.ts.MilestoneManagementComponent.onRegionChanged(milestone.component.ts:58)上评估)

selector.ts

export const selectRegionsState = createFeatureSelector<RegionsState>('regions');

export const selectRegion = (regionId: number) => createSelector(
  selectRegionsState,
  regionsState => regionsState.entities[regionId]
);

reducer.ts

export interface RegionsState extends EntityState<Region> {
  allRegionsLoaded: boolean;
}

export const regionsAdapter: EntityAdapter<Region> = createEntityAdapter<Region>();

export const initialRegionsState: RegionsState = regionsAdapter.getInitialState({
  allRegionsLoaded: false
});

export function regionsReducer(state = initialRegionsState, action: RegionActions): RegionsState {
...
}

component.ts

selectedRegion$: Observable<Region> = of({ id: 0, codeName: '', text: 'Select Region'});
...

onRegionChanged(regionId: number): void {
    this.selectedRegion$ = this.store.select(selectRegion(regionId));
}

export function regionsReducer(state = initialRegionsState, action: RegionActions): RegionsState {

}

1 个答案:

答案 0 :(得分:0)

必须将未定义的对象强制转换为Observable期望的类型。

selectedRegion$: Observable<Region> = of(<Region>{ id: 0, codeName: '', text: 'Select Region'});