How do I use the currency pipe in my Ionic2 app?
Do Ionic2 already support these kind of pipes?
If no, is that on the roadmap?
According the angular2 doc, Safari doesn’t support the angular2 currency pipe and therefore you have to add the polypill script in your website. Is that the same for an Ionic2 app?
The Date and Currency pipes need the ECMAScript Internationalization API. Safari and other older browsers don’t support it. We can add support with a polyfill.
yep saw that. but it means that in my case I will have to change / load the polyfill on the fly according the user locales, because I don’t target only one locale, that’s what I meant
since Ionic2 RC.0 is shipped with polyfill, both date and currency pipe now works in Safari but are still BUGGY in iOS. Seems that the problem is still in Angular2.
For that reason, I wrote my date pipe using momentjs too.
About the currency, furthermore to the issue, I also didn’t find any solution in Angular2 to load on the fly a different currency, seems that right now is only possible to specify a singly currency format for the all application. Therefore fck it, I also wrote my own currency pipe.
For those who want to achieve something similar, you could find
and a list of currency format (symbol, symbol before or after value) there
my only still open issue is that the javascript number.toLocaleString doesn’t seems to format correctly the number on iOS, but I can for the moment leave with that.
The currency pipe can’t give you it out of the box, he’s deep integrated in my code. But except that I really just used the list of countries and list of format I listed above
What I did I added this file to my assest folder and then in one of my service I load it, something like
this.http.get('./assets/currency/currency-format.json')
.map((res: Response) => res.json())
.subscribe((res: any) => {
// Do stuffs with json array
});
});
If for example you want to filter the result with the currency your are looking for
let whatIAmLookingFor: any;
Object.keys(res).map((key) => {
if (_.isEqual((key, filter)) { // I use underscore for comparison, filter would be your money like EUR
whatIAmLookingFor = res[key]; // --> the key your are looking for
}
});