4

It seems that development uses JIT and prod uses AOT, which is fine. However I'm trying to read the LOCALE_ID which seems to be null using JIT:

@Inject(LOCALE_ID) public localeId: string;

Comes out null.

I suspect I need to specify the language in the JIT setup. Per these instructions: https://angular.io/guide/i18n#merge-with-the-jit-compiler

However if I do this setup wouldn't that conflict with using AOT for translations later? - How can I access the default locale without it being null in JIT ? - How can I mix JIT and AOT in angular 6?

Dory Zidon
  • 10,497
  • 2
  • 25
  • 39

1 Answers1

2

Following the guide you provided will not break AoT compiled i18n settings, but it should not be needed. I've tried just injecting that token as you did in one of my components, and it was not null, but rather en-US. Also, when I did provide some other token in my app.module.ts (e.g. providers: [ { provide: LOCALE_ID, useValue: 'de' } ],, as https://angular.io/guide/i18n#merge-with-the-jit-compiler suggests), my injected token turned into de.

So to answer How can I access the default locale without it being null in JIT ?: you have to inject token (as you did), but you must not override it with some other value provided in app.module.ts.

With that in mind, there could be issue somewhere else in your code, so if you provide stackblitz or something else, we could perhaps pinpoint your problem.

crollywood
  • 523
  • 1
  • 6
  • 17