this.currentLoader.getTranslation is not a function
See original GitHub issueI’m trying to familiarize myself with this package. I loaded ng2-translate with the code available in the documentation with some changes (like providers etc.) but I’m still getting an issue,
this.currentLoader.getTranslation is not a function
Here is my code
import { Component, Injectable, provide } from '@angular/core';
import { Http } from '@angular/http';
import { bootstrap } from '@angular/platform-browser-dynamic';
import { TRANSLATE_PROVIDERS, TranslateService, TranslatePipe, TranslateLoader, TranslateStaticLoader } from 'ng2-translate/ng2-translate';
import { HTTP_PROVIDERS } from '@angular/http';
import { TransactionListcomponent } from './transactions/transaction-list.component';
@Component({
selector: 'my-app',
template: `
<div>
<h1>{{pageTitle}}</h1>
<h1>Hello, {{name}}!</h1>
Say "<b>{{ 'HELLO' | translate:'{value: "world"}' }}</b>" to: <input [value]="name" (input)="name = $event.target.value">
<br/>
Change language:
<select (change)="translate.use($event.target.value)">
<option *ngFor="#lang of ['fr', 'en']" [selected]="lang === translate.currentLang">{{lang}}</option>
</select>
<my-transactions></my-transactions>
</div>
`,
directives: [TransactionListcomponent],
pipes: [TranslatePipe],
providers: [TranslateService, TranslateLoader]
})
export class AppComponent {
pageTitle: string = 'Test app';
name: string = 'World';
constructor(translate: TranslateService) {
var userLang = navigator.language.split('-')[0]; // use navigator lang if available
userLang = /(fr|en)/gi.test(userLang) ? userLang : 'en';
// this language will be used as a fallback when a translation isn't found in the current language
translate.setDefaultLang('en');
console.log(translate)
// the lang to use, if the lang isn't available, it will use the current loader to get them
translate.use(userLang);
}
}
// Instantiate TranslateService in the bootstrap so that we can keep it as a singleton
bootstrap(AppComponent, [
HTTP_PROVIDERS,
{
provide: TranslateLoader,
useFactory: (http: Http) => new TranslateStaticLoader(http, 'app/assets/i18n', '.json'),
deps: [Http]
},
// use TranslateService here, and not TRANSLATE_PROVIDERS (which will define a default TranslateStaticLoader)
TranslateService
]);
Does anyone can help me?
Issue Analytics
- State:
- Created 7 years ago
- Comments:8
Top Results From Across the Web
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...
Read more >This.http.get is not a function at TranslateHttpLoader ...
I'm receiving the following error when I try to execute ionic serve: ERROR TypeError: this.http.get is not a function at TranslateHttpLoader ...
Read more >Getting started with translation in Angular 5 with ngx-translate
SetDefaultLang is used to set a fallback language when a translation isn't found in the current language. use the lang to use, if...
Read more >ngx-translate/core - UNPKG
currentLoader.getTranslation(lang).pipe(share());\n this.loadingTranslations = loadingTranslations.pipe(\n take(1),\n map((res: Object) => this.compiler.
Read more >Ngx-Translate: Cannot Read Property 'Currentlang ... - ADocLib
currentLoader.getTranslation is not a function. Here is my code import { Component Injectable provide } from '@angular/core'; import { Http } ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
user TranslateHttpLoader.
This is a very old question nevertheless I had the same problem today after migrating to Angular 8.
This may help someone.
Note: The problem was not coming from the migration to Angular 8.
app.module.ts
http-loader-multiple.provider.ts
I just removed the
multivalue and the problem was fixed.