2

我正在将 ngx-translate 用于其中一个 Angular 项目。当我尝试从 http post 请求加载翻译数据时,它失败了。代码如下:

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 { }

这是相同的 stackblitz:https ://stackblitz.com/edit/github-x4rjpw

4

0 回答 0