angular - 使用@ngrx/data,得到 "No EntityDefinition for entity type [x]"

标签 angular ngrx ngrx-data

我尝试使用 @ngrx/data 在 Angular 中创建一个简单的服务,但收到错误 EntityDefinition for entity type "Position".当组件运行时。

我的EntityMetadataMap是这样的:

const entityMetaData: EntityMetadataMap = {
  Employee: {},
  Position: {}
};

const pluralNames = { Employee: 'Employees', Position: 'Positions' };

export const entityConfig = {
  entityMetaData,
  pluralNames,
};

我的商店模块是这样的:

@NgModule({
  declarations: [],
  imports: [
    StoreModule.forRoot({}),
    EffectsModule.forRoot([]),
    StoreDevtoolsModule.instrument(),
    EntityDataModule.forRoot(entityConfig),
  ],
  providers: [
    {provide: DefaultDataServiceConfig, useValue: defaultDataServiceConfig},
    PositionsDataService
  ]

})
export class ItwStoreModule {
  constructor() {
    console.log(entityConfig);
  }
}

我的位置数据服务是这样的:

@Injectable({ providedIn: 'root' })
export class PositionsDataService extends EntityCollectionServiceBase<Position> {
  constructor(serviceFactory: EntityCollectionServiceElementsFactory) {
    super('Position', serviceFactory);
  }
}

我可以在模块设置和 EntityDataModule 中放置一个断点,我可以看到实体定义存在并且设置正确(作为 EntityDataModule.forRoot(entityConfig) 的一部分。

但是当服务的构造函数触发并调用super(...)时,在调试器中,我可以看到 EntityCollectionServiceElementsFactory 中没有 EntityDefinitions传入的内容(注意“定义”为空):

enter image description here

我在这里做错了什么? 显然,在存储模块启动和依赖项注入(inject)注入(inject) EntityCollectionServiceElementsFactory 之间。进入服务时,出现问题。

最佳答案

您有一个拼写错误:-

应该是entityMetadata

关于angular - 使用@ngrx/data,得到 "No EntityDefinition for entity type [x]",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58731183/

相关文章:

angular - ngrx/data error$ stream - 忽略之前的值

angular-ngrx-data - 获取 ngrx/data 的添加操作的结果或 HTTP 响应

angular - 支持 ngRx/data 的正确 Angular 版本是什么?

javascript - 在浏览器控制台中获取调度的 NGRX 项目

javascript - RxJS:只有在不同的情况下才去抖流

svg - 如何在 Angular2 中动态创建 SVG 组件?

javascript - 向多个父级发送事件以触发函数 Angular 5

Angular 延迟加载模块是从错误的 url 加载的

angular - 在 ngrx 上创建非记忆化选择器

angular - "TypeError: Cannot read property ' 在 ngrx 商店中发布 ' of undefined",仅在生产版本中具有 Angular