I’m trying to use Currency Pipe but keep getting the error:
Missing locale data for the locale “USD”.
I have this in my app.module.ts:
providers: [
{provide: ErrorHandler, useClass: IonicErrorHandler},
{provide: LOCALE_ID, useValue: "en-US"},
]
and in my typescript file I have the following:
public currencyPipe: CurrencyPipe = new CurrencyPipe('USD');
I use it like this:
toCurrency(value: any) {
if (this.currencyPipe == null) {
return '0';
}
return this.currencyPipe.transform(value, 'USD', true, '1.0-0');
}
Anyone have any suggestions? I’ve tried en-US and $ instead of USD, nothing has worked. In the ionic 2 beta releases this worked ok.
bump. still haven’t figured this one out. Anyone have ideas?
Mmmh looks good to me.
Have you debug the code, could you confirm that you land in your toCurrency
method and that this.currencyPipe
is not null?
Then, I didn’t check if it’s correct or not, but are maybe Pipes
not injectable?
See https://stackoverflow.com/a/41842214/5404186
if true, would mean
in module
declarations: [CurrencyPipe]
in your class
return (new CurrencyPipe('USD')).transform(value, 'USD', true, '1.0-0');
instead of
return this.currencyPipe.transform(value, 'USD', true, '1.0-0');
but like I said, not sure…
The solution was simple but somehow I missed it initially.
return (new CurrencyPipe('en-US')).transform(value, 'USD', true, '1.0-0');
There are all these posts about Locale that show up, but since I’m sticking with the English default I didn’t have to do anything but the above.
Thanks reedrichards for assisting!
1 Like
Thx you, I’m happy to have learn something about CurrencyPipe
which I didn’t use (yet)