From 1eff4b306f576e2644d559b3506ea13ff920e5a1 Mon Sep 17 00:00:00 2001 From: shamoon <4887959+shamoon@users.noreply.github.com> Date: Thu, 7 Mar 2024 07:04:32 -0800 Subject: [PATCH] Enhancement: better detection of default currency code (#6020) --- .../common/input/monetary/monetary.component.spec.ts | 6 ++++++ .../common/input/monetary/monetary.component.ts | 10 ++++++---- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/src-ui/src/app/components/common/input/monetary/monetary.component.spec.ts b/src-ui/src/app/components/common/input/monetary/monetary.component.spec.ts index 0a8608a1b..4106c01ec 100644 --- a/src-ui/src/app/components/common/input/monetary/monetary.component.spec.ts +++ b/src-ui/src/app/components/common/input/monetary/monetary.component.spec.ts @@ -56,4 +56,10 @@ describe('MonetaryComponent', () => { component.monetaryValue = 10.5 expect(component.value).toEqual('EUR10.50') }) + + it('should set the default currency code based on LOCALE_ID', () => { + expect(component.defaultCurrencyCode).toEqual('USD') // default + component = new MonetaryComponent('pt-BR') + expect(component.defaultCurrencyCode).toEqual('BRL') + }) }) diff --git a/src-ui/src/app/components/common/input/monetary/monetary.component.ts b/src-ui/src/app/components/common/input/monetary/monetary.component.ts index a7957b4c3..ebfd9b6bf 100644 --- a/src-ui/src/app/components/common/input/monetary/monetary.component.ts +++ b/src-ui/src/app/components/common/input/monetary/monetary.component.ts @@ -1,13 +1,14 @@ import { Component, - DEFAULT_CURRENCY_CODE, ElementRef, forwardRef, Inject, + LOCALE_ID, ViewChild, } from '@angular/core' import { NG_VALUE_ACCESSOR } from '@angular/forms' import { AbstractInputComponent } from '../abstract-input' +import { getLocaleCurrencyCode } from '@angular/common' @Component({ providers: [ @@ -24,11 +25,12 @@ import { AbstractInputComponent } from '../abstract-input' export class MonetaryComponent extends AbstractInputComponent { @ViewChild('currencyField') currencyField: ElementRef + defaultCurrencyCode: string - constructor( - @Inject(DEFAULT_CURRENCY_CODE) public defaultCurrencyCode: string - ) { + constructor(@Inject(LOCALE_ID) currentLocale: string) { super() + + this.defaultCurrencyCode = getLocaleCurrencyCode(currentLocale) } get currencyCode(): string {