简体   繁体   中英

How to retrieve only the currency symbol without formatting a price expression from angularjs currency filter

I have this span code in html:

<span class="input-group-addon">{{currency_symbol}}</span>

I am using localisation. So I am using i18n for angular. I am getting them correctly when I get the {{price_expression | currency}} {{price_expression | currency}} i get the correct format with a price, but for this span I only need the symbol of the currency how can I get this? Thanks!

You can use the $locale service

In your controller:

$scope.currency_symbol = $locale.NUMBER_FORMATS.CURRENCY_SYM;

But be careful!

Each locale exists in its own file. These files are generated, with very little human intervention from the Google Closure Library i18n files.

At a minimum they must expose an id. In general they expose a load of other stuff such as number and date information. But Angular does not guarantee that this is the case.

( Source )

So I suggest something like this:

$scope.currency_symbol = $locale.NUMBER_FORMATS.CURRENCY_SYM || '$';

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