Ngrx选择器未定义EntityAdapter

问题描述

在这方面转圈。每当我似乎使用选择器时,它都是不确定的。我检查了其他帖子以及我已经缺少的代码。使用选择器时,我总是变得不确定。我也有ngrx devtools安装程序。任何帮助将不胜感激。

组件:

import * as fromBusiness from '@app/@store/reducers/index';

    ngOnInit(): void {
    const id = this.params.id;
    this.business$ = this.store.pipe(select(fromBusiness.getBusinessEntityById(),{ id }))
    .pipe(
      map((business: BusinessModel) => {
        return this.business = business;
      }),);
    console.log(this.business);
  }

功能模块

StoreModule.forFeature('businesses',fromBusiness.businessFuncReducer),

减速器:

export interface State extends EntityState<BusinessModel> {}

export const adapter: EntityAdapter<BusinessModel> = createEntityAdapter<
  BusinessModel
>( {
  selectId: (business: BusinessModel) => business.id,});

export const initialState = adapter.getInitialState({});

export const businessReducer = createReducer(
  initialState,//reducer methods here,upsertone,addone etc
);

export function businessFuncReducer(state: State | undefined,action: Action) {
  return businessReducer(state,action);
}

export const businessFeatureSelector = createFeatureSelector<State>(
  'businesses'
);

export const {
  selectIds,selectEntities,selectAll,selectTotal,} = adapter.getSelectors();


export const getAllBusinesses = createSelector(
  businessFeatureSelector,selectAll
);

reducer.index.ts

export interface State {
  business: fromBusiness.State;
}

export const selectBusinessState = createFeatureSelector<fromBusiness.State>(
  'businesses'
);

export const selectBusinessEntities = createSelector(
  selectBusinessState,fromBusiness.selectEntities
);

export const getBusinessEntityById = () => {
  return createSelector(
    selectBusinessEntities,(entities: Dictionary<BusinessModel>,props: {id: string}) => {
      return entities[props.id];
    },);
};

对此表示感谢。花了2天没有解决方案。附件是devtools树的屏幕截图。

enter image description here

解决方法

我建议您将进口量增加一倍,并确保它是正确的。问题可能不在于使用的选择器,而是可能是父选择器之一?

,

结果不是选择器或模块。这就是我消费的方式。周围的示例对我不起作用,所以我做了一些稍微不同的方式。

相关问答

依赖报错 idea导入项目后依赖报错,解决方案:https://blog....
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下...
错误1:gradle项目控制台输出为乱码 # 解决方案:https://bl...
错误还原:在查询的过程中,传入的workType为0时,该条件不起...
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct...