I am trying to format currency when the page loads using AngularJS. But it doesn't work if I use the filter currency in ngModel.It seems to work only for {{var |currency}}.
P.S.:I want it to work on ngModel and I want the currency to be formatted when the page loads.
Try this:
HTML
<!doctype html>
<html ng-app="App">
<head>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/angularjs/1.2.0/angular.min.js"></script>
<script type="text/javascript" src="script.js"></script>
</head>
<body>
<div ng-controller="Ctrl">
<span>Amount1: {{amount1 | currency:"USD$"}}</span><br/>
<span>Symbol2: <input ng-model="symbol2"/></span><br/>
<span>Amount2: <input ng-model="amount2"/></span><br/>
</div>
</body>
</html>
JavaScript
angular.module('App', []);
function Ctrl($scope) {
$scope.amount1 = 1234.56;
$scope.symbol2 = 'USD$';
$scope.amount2 = '1234.56';
}
Plunker example
If that does not help, check this: Getting a currency format pattern from AngularJS filter
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With