Skip to content

Commit

Permalink
fix(common): initialize currencyCode in currencyPipe (#40505)
Browse files Browse the repository at this point in the history
currencyCode should be initialized with the injected default currency code

PR Close #40505
  • Loading branch information
vmohir authored and thePunderWoman committed Jun 3, 2021
1 parent dc6011b commit 0dad375
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
2 changes: 1 addition & 1 deletion packages/common/src/pipes/number_pipe.ts
Expand Up @@ -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;
Expand Down
5 changes: 5 additions & 0 deletions packages/common/test/pipes/number_pipe_spec.ts
Expand Up @@ -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'))
Expand Down

0 comments on commit 0dad375

Please sign in to comment.