|
7 | 7 | */ |
8 | 8 |
|
9 | 9 | import {ApplicationRef} from './application_ref'; |
10 | | -import {APP_ID_RANDOM_PROVIDER} from './application_tokens'; |
11 | | -import {StaticProvider} from './di'; |
12 | | -import {Inject, Optional, SkipSelf} from './di/metadata'; |
13 | | -import {DEFAULT_LOCALE_ID, USD_CURRENCY_CODE} from './i18n/localization'; |
14 | | -import {DEFAULT_CURRENCY_CODE, LOCALE_ID} from './i18n/tokens'; |
15 | 10 | import {NgModule} from './metadata'; |
16 | 11 |
|
17 | | -declare const $localize: {locale?: string}; |
18 | | - |
19 | | -export function _localeFactory(locale?: string): string { |
20 | | - return locale || getGlobalLocale(); |
21 | | -} |
22 | 12 | /** |
23 | | - * Work out the locale from the potential global properties. |
24 | | - * |
25 | | - * * Closure Compiler: use `goog.getLocale()`. |
26 | | - * * Ivy enabled: use `$localize.locale` |
27 | | - */ |
28 | | -export function getGlobalLocale(): string { |
29 | | - if (typeof ngI18nClosureMode !== 'undefined' && ngI18nClosureMode && |
30 | | - typeof goog !== 'undefined' && goog.getLocale() !== 'en') { |
31 | | - // * The default `goog.getLocale()` value is `en`, while Angular used `en-US`. |
32 | | - // * In order to preserve backwards compatibility, we use Angular default value over |
33 | | - // Closure Compiler's one. |
34 | | - return goog.getLocale(); |
35 | | - } else { |
36 | | - // KEEP `typeof $localize !== 'undefined' && $localize.locale` IN SYNC WITH THE LOCALIZE |
37 | | - // COMPILE-TIME INLINER. |
38 | | - // |
39 | | - // * During compile time inlining of translations the expression will be replaced |
40 | | - // with a string literal that is the current locale. Other forms of this expression are not |
41 | | - // guaranteed to be replaced. |
42 | | - // |
43 | | - // * During runtime translation evaluation, the developer is required to set `$localize.locale` |
44 | | - // if required, or just to provide their own `LOCALE_ID` provider. |
45 | | - return (typeof $localize !== 'undefined' && $localize.locale) || DEFAULT_LOCALE_ID; |
46 | | - } |
47 | | -} |
48 | | - |
49 | | -/** |
50 | | - * A built-in [dependency injection token](guide/glossary#di-token) |
51 | | - * that is used to configure the root injector for bootstrapping. |
52 | | - */ |
53 | | -export const APPLICATION_MODULE_PROVIDERS: StaticProvider[] = [ |
54 | | - APP_ID_RANDOM_PROVIDER, |
55 | | - { |
56 | | - provide: LOCALE_ID, |
57 | | - useFactory: _localeFactory, |
58 | | - deps: [[new Inject(LOCALE_ID), new Optional(), new SkipSelf()]] |
59 | | - }, |
60 | | - {provide: DEFAULT_CURRENCY_CODE, useValue: USD_CURRENCY_CODE}, |
61 | | -]; |
62 | | - |
63 | | -/** |
64 | | - * Configures the root injector for an app with |
65 | | - * providers of `@angular/core` dependencies that `ApplicationRef` needs |
66 | | - * to bootstrap components. |
67 | | - * |
68 | 13 | * Re-exported by `BrowserModule`, which is included automatically in the root |
69 | | - * `AppModule` when you create a new app with the CLI `new` command. |
| 14 | + * `AppModule` when you create a new app with the CLI `new` command. Eagerly injects |
| 15 | + * `ApplicationRef` to instantiate it. |
70 | 16 | * |
71 | 17 | * @publicApi |
72 | 18 | */ |
73 | | -@NgModule({providers: APPLICATION_MODULE_PROVIDERS}) |
| 19 | +@NgModule() |
74 | 20 | export class ApplicationModule { |
75 | 21 | // Inject ApplicationRef to make it eager... |
76 | 22 | constructor(appRef: ApplicationRef) {} |
|
0 commit comments