简体   繁体   中英

How to replace currency symbol in angularjs

I want to show one more currencies in a page. For example

$100,000 And 100,000€

When I use $filter('currency')(100000, '€') it returns €100,000. But I want it as 100,000€ The problem is I cannot replace the symbol. Any idea ?

You can always create a custom filter.

app.filter('customCurrency',['$filter', function(filter) {
  var currencyFilter = filter('currency');
  return function(amount, currencySymbol) {
    var value = currencyFilter(amount).substring(1);
    var currency = "";
    switch(currencySymbol) {
      case '$':
        currency = currencySymbol + value;
        break;
      case '€':
        currency = value + currencySymbol;
        break;
    }
    return currency;
  }}])

Here is the working example: http://plnkr.co/edit/IIWG18?p=preview

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM