Reputation: 11
I am entering amount in text box then it should append commas in between the amount (ex: I entered 123500 it should convert like 1,23,500.00 automatically when on blur) using angular js.
This should happen within the same input box.
Upvotes: 0
Views: 4940
Reputation: 48
Try this :
<html lang="en">
<head>
<script src="//ajax.googleapis.com/ajax/libs/angularjs/1.5.2/angular.min.js"></script>
</head>
<body ng-app="numberFilterExample">
<script>
angular.module('numberFilterExample', [])
.controller('ExampleController', ['$scope', function($scope) {
$scope.val = 1234.56789;
}]);
</script>
<div ng-controller="ExampleController">
<label>Enter number: <input ng-model='val'></label><br>
Default formatting: <span id='number-default'>{{val | number}}</span><br>
No fractions: <span>{{val | number:0}}</span><br>
Negative number: <span>{{-val | number:4}}</span>
</div>
</body>
</html>
Refer: http://plnkr.co/edit/mO257aew7YKXaIzSwS6G?p=preview
Upvotes: 1
Reputation: 4103
If this is for a currency input, you can use, ng-currency : https://github.com/aguirrel/ng-currency
<input type="text" model="yourModel" ng-currency />
An example is available here : http://plnkr.co/edit/u9mJqDH8UpwxDnOv8gZL?p=preview
The source code is pretty simple you can fork it, and adapt it to your code if you prefer.
Upvotes: 2