Angular 使用TranslateModule和HttpClientInMemoryWebAPI模块

Angular 使用TranslateModule和HttpClientInMemoryWebAPI模块,angular,angular5,angular-translate,Angular,Angular5,Angular Translate,我试图在我的angular proyect翻译和客户机内存web api中包含 由于我无法解决HttpClient,它们似乎存在一些不兼容 app.module.ts: import { BrowserModule } from '@angular/platform-browser'; import { ErrorHandler, LOCALE_ID, NgModule } from '@angular/core'; import { AppComponent } from './app.co

我试图在我的angular proyect翻译和客户机内存web api中包含

由于我无法解决HttpClient,它们似乎存在一些不兼容

app.module.ts:

import { BrowserModule } from '@angular/platform-browser';
import { ErrorHandler, LOCALE_ID, NgModule } from '@angular/core';

import { AppComponent } from './app.component';
import { routing } from './app.routing';
import { HttpClient, HttpClientModule } from '@angular/common/http';
import { FlexLayoutModule } from '@angular/flex-layout';
import { TranslateLoader, TranslateModule } from '@ngx-translate/core';
import { AppTranslateLoader } from './misc/app.translation-loader';
import { AppErrorHandler } from './misc/app.error-handler';
import { AppLanguageService } from './misc/app-language.service';
import { HttpClientInMemoryWebApiModule } from 'angular-in-memory-web-api';
import { InMemoryDataService }  from './in-memory-data.service';



export function getLocaleId(appLanguageService: AppLanguageService) {
  const sessionLanguage = appLanguageService.getSessionLanguage();
  return sessionLanguage.localeId;
 }

@NgModule({

declarations: [
     AppComponent,
],
imports: [
   HttpClientModule,
   HttpClientInMemoryWebApiModule.forRoot(
      InMemoryDataService, { dataEncapsulation: false }
    ),
    TranslateModule.forRoot({
      loader: {
        provide: TranslateLoader,
        useClass: AppTranslateLoader,
        deps: [HttpClient]
      }
    })
],
providers: [
  AppLanguageService,
  {provide: ErrorHandler, useClass: AppErrorHandler},
  {provide: LOCALE_ID, useFactory: getLocaleId, deps: 
   [AppLanguageService]}
],
 bootstrap: [AppComponent]
})
export class AppModule { }
如果我只导入翻译,它就可以工作,我不能尝试在内存中使用客户端,因为它在每个模块中都会使用

我想问题在于HttpClient,因为两者都使用它,而且我认为它们形成了不同的模块

当执行时,在chorme控制台中,我观察这个错误,在第页中没有显示任何错误

Error: [object Object]
at viewWrappedDebugError (core.js:9790)
at callWithDebugContext (core.js:15100)
at Object.debugCreateRootView [as createRootView] (core.js:14373)
at ComponentFactory_.create (core.js:11260)
at ComponentFactoryBoundToModule.create (core.js:4031)
at ApplicationRef.bootstrap (core.js:5855)
at eval (core.js:5582)
at Array.forEach (<anonymous>)
at PlatformRef._moduleDoBootstrap (core.js:5582)
at eval (core.js:5503)

Error: [object Object]
at viewWrappedDebugError (core.js:9790)
at callWithDebugContext (core.js:15100)
at Object.debugCreateRootView [as createRootView] (core.js:14373)
at ComponentFactory_.create (core.js:11260)
at ComponentFactoryBoundToModule.create (core.js:4031)
at ApplicationRef.bootstrap (core.js:5855)
at eval (core.js:5582)
at Array.forEach (<anonymous>)
at PlatformRef._moduleDoBootstrap (core.js:5582)
at eval (core.js:5503)

我找到了解决方案,有必要向HttpClientInMemoryWebAPI模块添加一个属性:

HttpClientInMemoryWebApiModule.forRoot(
   InMemoryDataService, {  passThruUnknownUrl: true, dataEncapsulation: false }
),

而且它有效

我找到了解决方案,有必要向HttpClientInMemoryWebAPI模块添加一个属性:

HttpClientInMemoryWebApiModule.forRoot(
   InMemoryDataService, {  passThruUnknownUrl: true, dataEncapsulation: false }
),

而且它有效

控制台中是否抛出错误?对不起,我忘记粘贴错误了!我编辑我的帖子控制台中是否出现任何错误?对不起,我忘记粘贴错误了!我编辑我的帖子