0

Brand new to ngrx.

My Id (capital Id) is not being mapped - system is trying to use id, leading to multiple console errors. I am using "@ngrx/data": "^8.6.0". I am using 8.?? because I am on Angular 8 (planning 9 in a month). Can I use an newer version?

I have temporarily mapped Id to id and it works but every backend call looks the same and it causes other issues to work around. how do I get my selectId registered (it can be default as well, all backend calls use Id.

I have a service registered manually - due to transformations to align data:

export class PregateService extends DefaultDataService<Pregate>
    super('Pregate', http, httpUrlGenerator);

I have my map registering the id override:

export function UpperId(entity: any): string {
  return entity.Id;
}

export const entityMetadata: EntityMetadataMap = {
  Pregate:  {
    selectId: UpperId,
  },
  // Stackrun: {},
  // Staging: {}
};

which is registered through the module:


@NgModule({
  declarations: [],
  providers: [{ provide: DefaultDataServiceConfig, useValue: defaultDataServiceConfig }],
  imports: [
    StoreModule.forRoot({}, {}),
    EffectsModule.forRoot([]),
    EntityDataModule.forRoot({ entityMetadata }),
    StoreDevtoolsModule.instrument(),
  ],
})
KenF
  • 544
  • 4
  • 14

1 Answers1

0

I was mixing my solution up. The service above was registered in a dynamically loaded service. Once I changed the right place it worked perfectly. I am sure other will get stuck by this sometime so posting an answer to remind others to check for it.

export class PreGateModule {
  readonly entityMetadata: EntityMetadataMap = {
    Pregate: {
      entityName: 'Pregate',
      selectId: UpperId,
    },
  };

  constructor(
    eds: EntityDefinitionService,
    data: EntityDataService,
    http: HttpClient,
    base: BaseApisProvider
  ) {
    const ps = new PregateService(http, base);
    data.registerService('Pregate', ps);
    eds.registerMetadataMap(this.entityMetadata);
  }
}
KenF
  • 544
  • 4
  • 14