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.

Rias
  • 1,956
  • 22
  • 33

1 Answers1

1

There is a new injectable object you can provide now, an instance of EntityServicesElements (imported from @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]);
  }
}
Todd Hansberger
  • 487
  • 4
  • 10