2017-07-28 15 views
6

Ionic 2モバイルアプリケーションを開発していて、ngx-translate機能を使用したいと考えています。私はNGX-翻訳によって予想パッケージの不一致があると思いますがIonic ngx-translateの 'Http'型の引数が 'Http'のパラメータに割り当てられません

Argument of type 'Http' is not assignable to parameter of type 'Http'. 
Property 'handler' is missing in type 'Http' 

import { TranslateModule, TranslateLoader } from '@ngx-translate/core'; 
import { TranslateHttpLoader } from '@ngx-translate/http-loader'; 
import { HttpModule, Http } from '@angular/http'; 
... 

export function createTranslateLoader(http: Http) { 
    return new TranslateHttpLoader(http, './assets/i18n/', '.json'); 
} 

エラーを与える: はチュートリアルの後、私はこのようなアプリモジュールに必要なファイルをインポートしています私は何をどのように把握することはできません。私の@角/ httpバージョンは4.3.2です 誰にも何をすべきか?

答えて

18

を使用してみてください以前のバージョンでは心配しないでください!あなただけの代わりにHttpClientを使用する必要がありますのHttp ..

don't forget to change the value of 'deps' constant and import the HttpClientModule in your module (or in your app.module)

「DEPS」定数の値を変更し、あなたのモジュールでHttpClientModuleをインポート(またはあなたのapp.moduleに)することを忘れないでください
14

は問題が原因の競合バージョンに、多分あなたはあなたの関数althought「@のNGX-変換/ HTTP-ローダー」の「^ 1.0.2」バージョンをインストールすることは可能ですされてHttpClientを

import {HttpClientModule, HttpClient} from '@angular/common/http'; 
import {TranslateModule, TranslateLoader} from '@ngx-translate/core'; 
import {TranslateHttpLoader} from '@ngx-translate/http-loader'; 
import {AppComponent} from "./app.component"; 

export function HttpLoaderFactory(http: HttpClient) { 
    return new TranslateHttpLoader(http, "./assets/i18n/", ".json"); 
} 

@NgModule({ 
    declarations: [ 
     AppComponent 
     ], 
    imports: [ 
     BrowserModule, 
     HttpClientModule, 
     TranslateModule.forRoot({ 
      loader: { 
       provide: TranslateLoader, 
       useFactory: HttpLoaderFactory, 
       deps: [HttpClient] 
      } 
     }) 
    ], 
    bootstrap: [AppComponent] 
}) 
export class AppModule { } 
+0

あなたの提案は私のために働いた。ありがとう!!! –

+0

は魅力的に働き、答えとして受け入れられるべきです。 –

+0

これが受け入れられる回答である必要があります。働いて、ありがとう。 –

関連する問題