Ram_T
Ram_T

Reputation: 8484

unable to insert html code inside filter?

Angualr JS code:

$scope.rupee = $filter('currency')($scope.dols * 67.33, 'INR', 3);

I am trying to insert html code inside this filter. That is instead of 'INR', I wish to get ₹ symbol. Please help me to solve this. And the problem is not getting the ₹ through filter. Instead of 'INR', I want to use &#8377 but it's not rendering as I expected.

html code:

<div>{{rupee}}</div>

Upvotes: 1

Views: 178

Answers (3)

Romesh
Romesh

Reputation: 2274

Modify your statement to

$scope.rupee = $filter('currency')($scope.dols * 67.33, '\u20B9', 3);

As you asked, "Can we write HTML code inside symbolFormat parameter?" Answer will be below:

Currency Filter function Number Formats

It takes a string parameter, so whatever string you are providing, it will be used to apply as currency symbol

For reference you can check Here

Upvotes: 2

daan.desmedt
daan.desmedt

Reputation: 3820

You can try like this:

{{ currency_expression | currency : symbol : fractionSize}}

$scope.rupee = $filter('currency')($scope.dols * 67.33, '₹', 3);

See all use cases (currency symbol & sign - in controller & directly on view):

<div ng-app ng-controller="RupeeCtrl">
    <b>From controller with sign</b><br/>
    {{rupeeSign}}
    <br/><br/>
    <b>From controller with code</b><br/>
    {{rupeeCode}}
    <br/><br/>
    <b>From view</b><br/>
    {{ price | currency:'&#8377;'}}      
</div>

function RupeeCtrl($scope, $filter) {
    $scope.price = 75.255;
    $scope.rupeeSign = $filter('currency')($scope.price, '₹', 3);
    $scope.rupeeCode = $filter('currency')($scope.price, '\u20B9', 3);
}

JSFiddle

Mixed with answer from @Romesh Jain

Upvotes: 1

Nikolai
Nikolai

Reputation: 318

This looks like a duplicate question to this: How to get specific currency symbol(rupee symbol in my case) in angular js instead of the default one (dollar $ symbol)

Just use this ASCII code for the Rupee symbol: ₹

See the ASCII code here: http://www.fileformat.info/info/unicode/char/20b9/index.htm

Upvotes: 0

Related Questions