I try to use the angular-in-memory-web-api (version 0.5.1). This works fine if I set up the "database" with local objects, but it fails if I try to get my data from local JSON files over an http request with following error:
Uncaught Error: Provider parse errors: Cannot instantiate cyclic dependency! HttpClient ("[ERROR ->]"): in NgModule AppModule in ./AppModule@-1:-1
as soon as I import the httpClient package into my service.
app.module.ts:
import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { HttpClientModule } from '@angular/common/http';
// Imports for loading & configuring the in-memory web api
import { HttpClientInMemoryWebApiModule } from 'angular-in-memory-web-api';
import { InMemoryDataService } from 'app/shared/services/in-memory-data.service';
import { AppComponent } from './app.component';
// other imports of app components
@NgModule({
imports: [
BrowserModule,
HttpClientModule,
HttpClientInMemoryWebApiModule.forRoot(InMemoryDataService), // always import after the HttpClientModule
],
declarations: [
AppComponent,
// ...
],
providers: [ // app wide services not concerning the problem ],
bootstrap: [ AppComponent ]
})
export class AppModule { }
in-memory-data.service.ts:
import { Injectable } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import { InMemoryDbService } from 'angular-in-memory-web-api';
import { RequestInfo } from 'angular-in-memory-web-api';
@Injectable()
export class InMemoryDataService implements InMemoryDbService {
// constructor(http: HttpClient) { // this creates the cyclic dependency
constructor() {
}
createDb(reqInfo?: RequestInfo) {
const db = {}
// fetch data from local JSON files and set up "database" object
return db;
}
}
Is this problem related to the HttpClientModule or is it an angular-in-memory-web-api problem?