Raul H
Raul H

Reputation: 305

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}} 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!

Upvotes: 0

Views: 1446

Answers (1)

rpadovani
rpadovani

Reputation: 7360

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 || '$';

Upvotes: 2

Related Questions