How do I inject a provider for ngrx Store for my Angular module?

Viewed 11

I'm using Angular 14 and ngrx/data. I want to add my DefaultDataService to my module. I have constructed this service

@Injectable()
export class MyObjectService extends DefaultDataService<MyObject> {
  private datePipe: DatePipe;

  constructor(
    http: HttpClient, 
    httpUrlGenerator: HttpUrlGenerator,
    datePipe: DatePipe
  ) {
    super('MyObject', http, httpUrlGenerator, {
      root: 'http://localhost:8080/test/api',
      timeout: 3000,
    });
    this.datePipe = datePipe;
  }
    ...
}

and attempted to add it to my module like so

@NgModule({
  declarations: [
    ...
  ],
  imports: [
    ...
    HttpClientModule,
    StoreModule.forRoot({}),
    EffectsModule.forRoot([]),
    EntityDataModule.forRoot({}),
  ],
  exports: [
    MyObjectsComponent
  ],
  providers: [
    MyObjectService, 
    EntityDataService, 
    EntityDefinitionService,
    { provide: Store, useValue: {} },
  ]
})
export class MyModule { 
  constructor(entityDefinitionService: EntityDefinitionService) {
    entityDefinitionService.registerMetadataMap(myObjectEntityMetaData);
  }
}

but when I load my web page, I get this JS error

ERROR Error: Uncaught (in promise): NullInjectorError: NullInjectorError: No provider for Store!
get@http://localhost:8000/node_modules_angular_core_fesm2020_core_mjs.js:7777:21
get@http://localhost:8000/node_modules_angular_core_fesm2020_core_mjs.js:8280:27
get@http://localhost:8000/node_modules_angular_core_fesm2020_core_mjs.js:8280:27
injectInjectorOnly@http://localhost:8000/node_modules_angular_core_fesm2020_core_mjs.js:5944:29
ɵɵinject@http://localhost:8000/node_modules_angular_core_fesm2020_core_mjs.js:5949:59
EffectsRunner_Factory@http://localhost:8000/node_modules_ngrx_effects_fesm2020_ngrx-effects_mjs-_a49a0.js:509:149
hydrate@http://localhost:8000/node_modules_angular_core_fesm2020_core_mjs.js:8394:29
get@http://localhost:8000/node_modules_angular_core_fesm2020_core_mjs.js:8270:23
get@http://localhost:8000/node_modules_angular_core_fesm2020_core_mjs.js:8280:27
get@http://localhost:8000/node_modules_angular_core_fesm2020_core_mjs.js:8280:27
injectInjectorOnly@http://localhost:8000/node_mod…

I'm already including "StoreModule.forRoot({})," so what else does the app need/want?

0 Answers
Related