fix(common): initialize currencyCode in currencyPipe (#40505)

currencyCode should be initialized with the injected default currency code

PR Close #40505
This commit is contained in:
Vahid Mohammadi 2021-05-05 11:44:18 +04:30 committed by Jessica Janiuk
parent c964ad66d4
commit 374fa2c26f
2 changed files with 6 additions and 1 deletions

View File

@ -253,7 +253,7 @@ export class CurrencyPipe implements PipeTransform {
display?: 'code'|'symbol'|'symbol-narrow'|string|boolean, digitsInfo?: string,
locale?: string): string|null;
transform(
value: number|string|null|undefined, currencyCode?: string,
value: number|string|null|undefined, currencyCode: string = this._defaultCurrencyCode,
display: 'code'|'symbol'|'symbol-narrow'|string|boolean = 'symbol', digitsInfo?: string,
locale?: string): string|null {
if (!isValue(value)) return null;

View File

@ -140,6 +140,11 @@ import {ɵregisterLocaleData, ɵunregisterLocaleData} from '@angular/core';
expect(pipe.transform(5.1234, 'DKK', '', '', 'da')).toEqual('5,12');
});
it('should use the injected default currency code if none is provided', () => {
const clpPipe = new CurrencyPipe('en-US', 'CLP');
expect(clpPipe.transform(1234)).toEqual('CLP1,234');
});
it('should support any currency code name', () => {
// currency code is unknown, default formatting options will be used
expect(pipe.transform(5.1234, 'unexisting_ISO_code', 'symbol'))