feat(common): allow default currency code to be configurable (#34771)

Default currency code in CurrencyPipe is currently hardcoded to USD
and is not configurable. This commit allows the default currency code
to be configurable by adding a DEFAULT_CURRENCY_CODE injection token.

Example:
```
providers: [{ provide: DEFAULT_CURRENCY_CODE, useValue: "GBP" }]
...
{{ 123.45 | currency }} // outputs £123.45 as opposed to always $123.45 before
```

Closes: #25461

PR Close #34771
This commit is contained in:
Hayouung
2019-12-14 10:39:41 +00:00
committed by atscott
parent d318249125
commit 965f5575c7
9 changed files with 52 additions and 10 deletions

View File

@ -6,7 +6,7 @@
* found in the LICENSE file at https://angular.io/license
*/
import {LOCALE_ID} from '@angular/core';
import {DEFAULT_CURRENCY_CODE, LOCALE_ID} from '@angular/core';
import {ivyEnabled} from '@angular/private/testing';
import {getLocaleId} from '../src/render3';
@ -19,6 +19,11 @@ import {describe, expect, inject, it} from '../testing/src/testing_internal';
it('should set the default locale to "en-US"',
inject([LOCALE_ID], (defaultLocale: string) => { expect(defaultLocale).toEqual('en-US'); }));
it('should set the default currency code to "USD"',
inject([DEFAULT_CURRENCY_CODE], (defaultCurrencyCode: string) => {
expect(defaultCurrencyCode).toEqual('USD');
}));
if (ivyEnabled) {
it('should set the ivy locale with the configured LOCALE_ID', () => {
TestBed.configureTestingModule({providers: [{provide: LOCALE_ID, useValue: 'fr'}]});