I followed the response of this thread , and I have the following solution:
import { LOCALE_ID } from '@angular/core'; @NgModule({ // ... providers: [... {provide: LOCALE_ID, deps: [SettingsService], // some service handling global settings useFactory: getLanguage // returns locale string } ] // ... }) export class AppModule { } // the following function is required (for Angular 4.1.1!!!) export function getLanguage(settingsService: SettingsService) { return settingsService.getLanguage(); }
Note: Using an additional function prevents the error Function calls are not supported. Consider replacing the function or lambda with a reference to an exported function Function calls are not supported. Consider replacing the function or lambda with a reference to an exported function !!!!
and i create a class
import { Injectable } from '@angular/core'; @Injectable() export class SettingsService { currentLang: string; constructor() { this.currentLang = 'en'; } setLanguage(lang: string) { this.currentLang = lang; } getLanguage() { return this.currentLang; } }
which changes LOCALE_ID on the fly LOCALE_ID
source share