2

I try to create a Sub-class EntityServices for application class convenience according to the NGRX/data documentation at https://ngrx.io/guide/data/entity-services#sub-class-entityservices-for-application-class-convenience

Unfortunately the provided example doesn't seem to work with the latest version of ngrx/data 8.5.2. The example looks like:

@Injectable()
  export class AppEntityServices extends EntityServicesBase {
    constructor(
      public readonly store: Store<EntityCache>,
      public readonly entityCollectionServiceFactory: EntityCollectionServiceFactory,

      // Inject custom services, register them with the EntityServices, and expose in API.
      public readonly heroesService: HeroesService,
      public readonly villainsService: VillainsService
    ) {
      super(store, entityCollectionServiceFactory);
      this.registerEntityCollectionServices([heroesService, villainsService]);
  }
}

When I use the example with my code, I get the following TypeScript error:

Error: (parameter) entityCollectionServiceFactory: EntityCollectionServiceFactory Expected 1 arguments, but got 2. ts(2554)

for the line when I call the parents constructor super(...) It looks like EntityServicesBases constructor is only accepting 1 argument of type EntityServicesElements. But how can I create my custom AppEntityService? I couldn't find any working example.

4

1 回答 1

1

您现在可以提供一个新的可注入对象,一个EntityServicesElements(从 导入@ngrx/data)的实例:

@Injectable()
export class AppEntityServices extends EntityServicesBase {
  constructor(
    entityServicesElements: EntityServicesElements,
    // Inject custom services, register them with the EntityServices, and expose in API.
    public readonly heroesService: HeroesService,
    public readonly villainsService: VillainsService
  ) {
    super(entityServicesElements);
    this.registerEntityCollectionServices([heroesService, villainsService]);
  }
}
于 2020-01-16T14:35:08.923 回答