angular-in-memory-web-api
(バージョン0.5.1)を使用しようとしています。私は地元のオブジェクトと「データベース」を設定する場合、これは正常に動作しますが、私は次のエラーでのHTTPリクエストを介してローカルのJSONファイルから自分のデータを取得しようとする場合、それは失敗します。できるだけ早く私はインポートとしてメモリ内の角度のWebクライアントとhttpClientの循環依存関係
Uncaught Error: Provider parse errors: Cannot instantiate cyclic dependency! HttpClient ("[ERROR ->]"): in NgModule AppModule in ./[email protected]:-1
httpClient
私のサービスにパッケージ。
app.module.ts:メモリ内の-data.service.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 { }
:
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;
}
}
がHttpClientModule
に関連したこの問題ですか、それはangular-in-memory-web-api
問題ですか?
jsonファイルへのリクエストを行う場合は、InMemoryWebApiModuleを使用しないでください。そのためには、httpclientを使ってhttp getリクエストを作成してください。 – Alex
JSONファイルからインメモリデータベースサービスを初期化することは、私がやりたいことなので、かなりのデータであるためJSONファイルをリクエストする必要があります。 – jowey
はい、jsonファイルをリクエストしてください。inmemorywebapiではありません。 – Alex