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')
+ })
})
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: [
export class MonetaryComponent extends AbstractInputComponent<string> {
@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 {