4
I have a problem with the coin mask with Angularjs.
I found this thread in Stackoverflow in English. The mask works beauty by typing in input and arrives right in the controller, but when I send formatted controller to the screen does not roll.
Here have an example.
- Excerpt from the code of Directive
app.directive('format', ['$filter',
function ($filter) {
return {
require: '?ngModel',
link: function (scope, elem, attrs, ctrl) {
if (!ctrl) return;
ctrl.$formatters.unshift(function (a) {
return $filter(attrs.format)(ctrl.$modelValue)
});
ctrl.$parsers.unshift(function (viewValue) {
elem.priceFormat({
prefix: '',
centsSeparator: ',',
thousandsSeparator: '.'
});
return elem[0].value;
});
}
};
}
]);
- Page code
<!DOCTYPE html>
<html ng-app="plunker">
<head>
<meta charset="utf-8" />
<title>AngularJS Plunker</title>
<script>
document.write('<base href="' + document.location + '" />');
</script>
<link rel="stylesheet" href="style.css" />
<script type="text/javascript" src="http://code.jquery.com/jquery-1.8.3.js"> </script>
<script data-require="[email protected]" src="http://code.angularjs.org/1.2.9/angular.js" data-semver="1.2.9"></script>
<script src="app.js"></script>
</head>
<body ng-controller="MainCtrl">
<div>
<br/>Original Example
<input type="text" ng-model="test" format="number" />
<pre>{{test|json}}</pre><br/>
Example 1<input type="text" ng-model="test_2" format="number" />
<pre>{{test_2|json}}</pre><br/>
Example 2<input type="text" ng-model="test_3" format="number" />
<pre>{{test_3|json}}</pre><br/>
</div>
</body>
</html>
I didn’t understand the problem. The example here is working perfectly, both the
input
as to thepre
with the value below.– fiatjaf
take a look at example 2, command formatted in the Brazilian style '', '999.999,99', only that it does not appear in the input, but in example 1 it appears in the field but because the formatting is in the American style','999,999.99'.
– Diogo Calazans