fix(ivy): set LOCALE_ID when using the injector (#31566)
In `BrowserModule` the value of `LOCALE_ID` is defined in the `APPLICATION_MODULE_PROVIDERS` after `APP_INITIALIZER` has run. This PR ensures that `LOCALE_ID` is also set for ivy at the same moment which allows the application to fetch the locale from a backend (for example). Fixes #31465 FW-1436 #resolve PR Close #31566
This commit is contained in:

committed by
Andrew Kushnir

parent
40a0666651
commit
5296c04f61
@ -8,15 +8,16 @@
|
||||
|
||||
import {Observable, Observer, Subscription, merge} from 'rxjs';
|
||||
import {share} from 'rxjs/operators';
|
||||
|
||||
import {ApplicationInitStatus} from './application_init';
|
||||
import {APP_BOOTSTRAP_LISTENER, PLATFORM_INITIALIZER} from './application_tokens';
|
||||
import {getCompilerFacade} from './compiler/compiler_facade';
|
||||
import {Console} from './console';
|
||||
import {Injectable, InjectionToken, Injector, StaticProvider} from './di';
|
||||
import {ErrorHandler} from './error_handler';
|
||||
import {DEFAULT_LOCALE_ID} from './i18n/localization';
|
||||
import {LOCALE_ID} from './i18n/tokens';
|
||||
import {Type} from './interface/type';
|
||||
import {ivyEnabled} from './ivy_switch';
|
||||
import {COMPILER_OPTIONS, CompilerFactory, CompilerOptions} from './linker/compiler';
|
||||
import {ComponentFactory, ComponentRef} from './linker/component_factory';
|
||||
import {ComponentFactoryBoundToModule, ComponentFactoryResolver} from './linker/component_factory_resolver';
|
||||
@ -26,7 +27,7 @@ import {isComponentResourceResolutionQueueEmpty, resolveComponentResources} from
|
||||
import {WtfScopeFn, wtfCreateScope, wtfLeave} from './profile/profile';
|
||||
import {assertNgModuleType} from './render3/assert';
|
||||
import {ComponentFactory as R3ComponentFactory} from './render3/component_ref';
|
||||
import {DEFAULT_LOCALE_ID, setLocaleId} from './render3/i18n';
|
||||
import {setLocaleId} from './render3/i18n';
|
||||
import {NgModuleFactory as R3NgModuleFactory} from './render3/ng_module_ref';
|
||||
import {Testability, TestabilityRegistry} from './testability/testability';
|
||||
import {isDevMode} from './util/is_dev_mode';
|
||||
@ -264,8 +265,10 @@ export class PlatformRef {
|
||||
throw new Error('No ErrorHandler. Is platform module (BrowserModule) included?');
|
||||
}
|
||||
// If the `LOCALE_ID` provider is defined at bootstrap we set the value for runtime i18n (ivy)
|
||||
const localeId = moduleRef.injector.get(LOCALE_ID, DEFAULT_LOCALE_ID);
|
||||
setLocaleId(localeId);
|
||||
if (ivyEnabled) {
|
||||
const localeId = moduleRef.injector.get(LOCALE_ID, DEFAULT_LOCALE_ID);
|
||||
setLocaleId(localeId || DEFAULT_LOCALE_ID);
|
||||
}
|
||||
moduleRef.onDestroy(() => remove(this._modules, moduleRef));
|
||||
ngZone !.runOutsideAngular(
|
||||
() => ngZone !.onError.subscribe(
|
||||
|
Reference in New Issue
Block a user