我将ngx-translate用于其中一个有角项目。当我尝试从http发布请求加载翻译数据时,它失败了。代码如下:
import { BrowserModule } from '@angular/platform-browser';
import { NgModule, Injectable } from '@angular/core';
import { AppComponent } from './app.component';
import {HttpClient, HttpClientModule} from '@angular/common/http';
import {TranslateModule, TranslateLoader} from '@ngx-translate/core';
@Injectable({
providedIn: 'root'
})
export class TranslationService {
constructor(private http: HttpClient) { }
getTranslation() {
return this.http.post('https://dev-
api.chilindo.com/api/Language/v1/PageText', { 'name': 'Master',
language: 'en', domain:'th' }).subscribe((resp:any)=>{
return resp;
})
}
}
@NgModule({
declarations: [
AppComponent
],
imports: [
BrowserModule,
HttpClientModule,
TranslateModule.forRoot({
loader: {
provide: TranslateLoader,
useClass : TranslationService,
deps: [HttpClient]
}
})
],
providers: [],
bootstrap: [AppComponent]
})
export class AppModule { }