I am trying to use @ngrx/data to create a simple service in Angular, and am receiving the error EntityDefinition for entity type "Position".
when the component runs.
My EntityMetadataMap is this:
const entityMetaData: EntityMetadataMap = {
Employee: {},
Position: {}
};
const pluralNames = { Employee: 'Employees', Position: 'Positions' };
export const entityConfig = {
entityMetaData,
pluralNames,
};
and my store module is this:
@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);
}
}
and my data service for position is this:
@Injectable({ providedIn: 'root' })
export class PositionsDataService extends EntityCollectionServiceBase<Position> {
constructor(serviceFactory: EntityCollectionServiceElementsFactory) {
super('Position', serviceFactory);
}
}
I can put a break point in the module setup and in EntityDataModule and I can see that the entity definition exists and is getting set correctly (as part of EntityDataModule.forRoot(entityConfig)
.
But when the constructor of the service fires and calls super(...)
, in the debugger, I can see that there are no EntityDefinitions in the EntityCollectionServiceElementsFactory
that is passed in (note the "definitions" are empty):
What am I doing wrong here?
Obviously, between when the store module is initiated and when the dependency injection injects the EntityCollectionServiceElementsFactory
into the service, something is going wrong.
You have a typo:-
It should be entityMetadata