Core: not working in angular5

Created on 19 Nov 2017  路  8Comments  路  Source: ngx-translate/core

Hi,
ngx-translate was working fine with angular4 in shared module. I mean, if i change language in one place, it got affected through out the entire app. But after upgrading to angular5, its not working now.

I'm getting this error...

ERROR Error: Uncaught (in promise): Error: StaticInjectorError[TranslateStore]: 
  StaticInjectorError[TranslateStore]: 
    NullInjectorError: No provider for TranslateStore!
Error: StaticInjectorError[TranslateStore]: 
  StaticInjectorError[TranslateStore]: 
    NullInjectorError: No provider for TranslateStore!
    at _NullInjector.get (core.js:923)
    at resolveToken (core.js:1211)
    at tryResolveToken (core.js:1153)
    at StaticInjector.get (core.js:1024)
    at resolveToken (core.js:1211)
    at tryResolveToken (core.js:1153)
    at StaticInjector.get (core.js:1024)
    at resolveNgModuleDep (core.js:10585)
    at _createClass (core.js:10630)
    at _createProviderInstance$1 (core.js:10596)
    at _NullInjector.get (core.js:923)
    at resolveToken (core.js:1211)
    at tryResolveToken (core.js:1153)
    at StaticInjector.get (core.js:1024)
    at resolveToken (core.js:1211)
    at tryResolveToken (core.js:1153)
    at StaticInjector.get (core.js:1024)
    at resolveNgModuleDep (core.js:10585)
    at _createClass (core.js:10630)
    at _createProviderInstance$1 (core.js:10596)
    at resolvePromise (zone.js:824)
    at resolvePromise (zone.js:795)
    at eval (zone.js:873)
    at ZoneDelegate.invokeTask (zone.js:425)
    at Object.onInvokeTask (core.js:4620)
    at ZoneDelegate.invokeTask (zone.js:424)
    at Zone.runTask (zone.js:192)
    at drainMicroTaskQueue (zone.js:602)
    at ZoneTask.invokeTask (zone.js:503)
    at ZoneTask.invoke (zone.js:488)

please help me to fix this issue.

ngx-translate version I'm using is 8.

Most helpful comment

My solution

import {HttpClient, HttpClientModule} from '@angular/common/http';

export function HttpLoaderFactory(http: HttpClient) {
  return new TranslateHttpLoader(http);
}

imports: [
    ...
    HttpClientModule,
    TranslateModule.forRoot({
      loader: {
        provide: TranslateLoader,
        useFactory: HttpLoaderFactory,
        deps: [HttpClient]
      }
    }),
   ...
  ],

Just add HttpClientModule to your imports

All 8 comments

You have to change the http to httpclient in your app.module.ts :

export function HttpLoaderFactory(http: HttpClient) {
  return new TranslateHttpLoader(http)
}
@NgModule({
  imports: [
    ...
    TranslateModule.forRoot({
      loader: {
        provide: TranslateLoader,
        useFactory: HttpLoaderFactory,
        deps: [HttpClient]
      }
    })
  ],

I got the same issue since Im trying to create an external module which uses translation for template. Some of the pipes and service cannot be found.

My solution

import {HttpClient, HttpClientModule} from '@angular/common/http';

export function HttpLoaderFactory(http: HttpClient) {
  return new TranslateHttpLoader(http);
}

imports: [
    ...
    HttpClientModule,
    TranslateModule.forRoot({
      loader: {
        provide: TranslateLoader,
        useFactory: HttpLoaderFactory,
        deps: [HttpClient]
      }
    }),
   ...
  ],

Just add HttpClientModule to your imports

I din't do anything. But when i opened my lap next day, it works fine just like it worked on angular4. Don't know why it didn't worked on first day. I'm closing this issue.

I still have the same issue and I'm very stuck on it... Has anyone any new about that? Great thanks in advance

We've been using ngx-translate with angular 5 for a while now and did not encounter any issues if you refactor your code to use httpclient

@dkabul I have same issue,
my case was:

  1. I have an angular library based on https://github.com/dherges/ng-packagr
  1. I added it to externals as @ovione commented : https://github.com/dherges/ng-packagr/issues/259

Issue with ngx-translate 9.1.1 version
I am using angualar 5
./node_modules/@ngx-translate/core/fesm5/ngx-translate-core.js

Module build failed: Error: ENOENT: no such file or directory, open node_modules\@ngx-translate\core\fesm5\ngx-translate-core.js'

Was this page helpful?
0 / 5 - 0 ratings