Sushil Kumar Gupta
Sushil Kumar Gupta

Reputation: 190

Error: this.currentLoader.getTranslation(...).pipe is not a function

I am using ngx-translate for one of the angular projects. When I try to load translation data from http post request, it is failing. The code is as below:

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

This is stackblitz for the same: https://stackblitz.com/edit/github-x4rjpw

Upvotes: 2

Views: 2623

Answers (0)

Related Questions