fix(common): do not override locale provided on bootstrap (#13654)
Closes #13607
This commit is contained in:
		
							parent
							
								
									35f9a1c2cb
								
							
						
					
					
						commit
						2dd6280ab8
					
				| @ -11,6 +11,7 @@ import {ApplicationInitStatus} from './application_init'; | |||||||
| import {ApplicationRef, ApplicationRef_} from './application_ref'; | import {ApplicationRef, ApplicationRef_} from './application_ref'; | ||||||
| import {APP_ID_RANDOM_PROVIDER} from './application_tokens'; | import {APP_ID_RANDOM_PROVIDER} from './application_tokens'; | ||||||
| import {IterableDiffers, KeyValueDiffers, defaultIterableDiffers, defaultKeyValueDiffers} from './change_detection/change_detection'; | import {IterableDiffers, KeyValueDiffers, defaultIterableDiffers, defaultKeyValueDiffers} from './change_detection/change_detection'; | ||||||
|  | import {Inject, Optional, SkipSelf} from './di/metadata'; | ||||||
| import {LOCALE_ID} from './i18n/tokens'; | import {LOCALE_ID} from './i18n/tokens'; | ||||||
| import {Compiler} from './linker/compiler'; | import {Compiler} from './linker/compiler'; | ||||||
| import {ViewUtils} from './linker/view_utils'; | import {ViewUtils} from './linker/view_utils'; | ||||||
| @ -24,6 +25,10 @@ export function _keyValueDiffersFactory() { | |||||||
|   return defaultKeyValueDiffers; |   return defaultKeyValueDiffers; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | export function _localeFactory(locale?: string): string { | ||||||
|  |   return locale || 'en-US'; | ||||||
|  | } | ||||||
|  | 
 | ||||||
| /** | /** | ||||||
|  * This module includes the providers of @angular/core that are needed |  * This module includes the providers of @angular/core that are needed | ||||||
|  * to bootstrap components via `ApplicationRef`. |  * to bootstrap components via `ApplicationRef`. | ||||||
| @ -41,7 +46,11 @@ export function _keyValueDiffersFactory() { | |||||||
|     AnimationQueue, |     AnimationQueue, | ||||||
|     {provide: IterableDiffers, useFactory: _iterableDiffersFactory}, |     {provide: IterableDiffers, useFactory: _iterableDiffersFactory}, | ||||||
|     {provide: KeyValueDiffers, useFactory: _keyValueDiffersFactory}, |     {provide: KeyValueDiffers, useFactory: _keyValueDiffersFactory}, | ||||||
|     {provide: LOCALE_ID, useValue: 'en-US'}, |     { | ||||||
|  |       provide: LOCALE_ID, | ||||||
|  |       useFactory: _localeFactory, | ||||||
|  |       deps: [[new Inject(LOCALE_ID), new Optional(), new SkipSelf()]] | ||||||
|  |     }, | ||||||
|   ] |   ] | ||||||
| }) | }) | ||||||
| export class ApplicationModule { | export class ApplicationModule { | ||||||
|  | |||||||
| @ -14,4 +14,4 @@ export function main() { | |||||||
|     it('should set the default locale to "en-US"', |     it('should set the default locale to "en-US"', | ||||||
|        inject([LOCALE_ID], (defaultLocale: string) => { expect(defaultLocale).toEqual('en-US'); })); |        inject([LOCALE_ID], (defaultLocale: string) => { expect(defaultLocale).toEqual('en-US'); })); | ||||||
|   }); |   }); | ||||||
| } | } | ||||||
|  | |||||||
| @ -6,12 +6,12 @@ | |||||||
|  * found in the LICENSE file at https://angular.io/license
 |  * found in the LICENSE file at https://angular.io/license
 | ||||||
|  */ |  */ | ||||||
| 
 | 
 | ||||||
| import {APP_INITIALIZER, CUSTOM_ELEMENTS_SCHEMA, Compiler, Component, Directive, ErrorHandler, Inject, Input, NgModule, OnDestroy, PLATFORM_INITIALIZER, Pipe, Provider, VERSION, createPlatformFactory} from '@angular/core'; | import {APP_INITIALIZER, CUSTOM_ELEMENTS_SCHEMA, Compiler, Component, Directive, ErrorHandler, Inject, Input, LOCALE_ID, NgModule, OnDestroy, PLATFORM_INITIALIZER, Pipe, Provider, VERSION, createPlatformFactory} from '@angular/core'; | ||||||
| import {ApplicationRef, destroyPlatform} from '@angular/core/src/application_ref'; | import {ApplicationRef, destroyPlatform} from '@angular/core/src/application_ref'; | ||||||
| import {Console} from '@angular/core/src/console'; | import {Console} from '@angular/core/src/console'; | ||||||
| import {ComponentRef} from '@angular/core/src/linker/component_factory'; | import {ComponentRef} from '@angular/core/src/linker/component_factory'; | ||||||
| import {Testability, TestabilityRegistry} from '@angular/core/src/testability/testability'; | import {Testability, TestabilityRegistry} from '@angular/core/src/testability/testability'; | ||||||
| import {AsyncTestCompleter, Log, afterEach, beforeEach, beforeEachProviders, describe, iit, inject, it} from '@angular/core/testing/testing_internal'; | import {AsyncTestCompleter, Log, afterEach, beforeEach, beforeEachProviders, describe, inject, it} from '@angular/core/testing/testing_internal'; | ||||||
| import {BrowserModule} from '@angular/platform-browser'; | import {BrowserModule} from '@angular/platform-browser'; | ||||||
| import {platformBrowserDynamic} from '@angular/platform-browser-dynamic'; | import {platformBrowserDynamic} from '@angular/platform-browser-dynamic'; | ||||||
| import {getDOM} from '@angular/platform-browser/src/dom/dom_adapter'; | import {getDOM} from '@angular/platform-browser/src/dom/dom_adapter'; | ||||||
| @ -109,7 +109,8 @@ class DummyConsole implements Console { | |||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| class TestModule {} | class TestModule {} | ||||||
| function bootstrap(cmpType: any, providers: Provider[] = []): Promise<any> { | function bootstrap( | ||||||
|  |     cmpType: any, providers: Provider[] = [], platformProviders: Provider[] = []): Promise<any> { | ||||||
|   @NgModule({ |   @NgModule({ | ||||||
|     imports: [BrowserModule], |     imports: [BrowserModule], | ||||||
|     declarations: [cmpType], |     declarations: [cmpType], | ||||||
| @ -119,7 +120,7 @@ function bootstrap(cmpType: any, providers: Provider[] = []): Promise<any> { | |||||||
|   }) |   }) | ||||||
|   class TestModule { |   class TestModule { | ||||||
|   } |   } | ||||||
|   return platformBrowserDynamic().bootstrapModule(TestModule); |   return platformBrowserDynamic(platformProviders).bootstrapModule(TestModule); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| export function main() { | export function main() { | ||||||
| @ -281,6 +282,17 @@ export function main() { | |||||||
|          }); |          }); | ||||||
|        })); |        })); | ||||||
| 
 | 
 | ||||||
|  |     it('should not override locale provided during bootstrap', | ||||||
|  |        inject([AsyncTestCompleter], (async: AsyncTestCompleter) => { | ||||||
|  |          const refPromise = | ||||||
|  |              bootstrap(HelloRootCmp, [testProviders], [{provide: LOCALE_ID, useValue: 'fr-FR'}]); | ||||||
|  | 
 | ||||||
|  |          refPromise.then(ref => { | ||||||
|  |            expect(ref.injector.get(LOCALE_ID)).toEqual('fr-FR'); | ||||||
|  |            async.done(); | ||||||
|  |          }); | ||||||
|  |        })); | ||||||
|  | 
 | ||||||
|     it('should avoid cyclic dependencies when root component requires Lifecycle through DI', |     it('should avoid cyclic dependencies when root component requires Lifecycle through DI', | ||||||
|        inject([AsyncTestCompleter], (async: AsyncTestCompleter) => { |        inject([AsyncTestCompleter], (async: AsyncTestCompleter) => { | ||||||
|          const refPromise = bootstrap(HelloRootCmp4, testProviders); |          const refPromise = bootstrap(HelloRootCmp4, testProviders); | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user