当用户输入一个数字时,我有一个数字输入类型,它应该以印度格式显示
Example: 500000 should be displayed as 50,000
如果不使用 javascript,我怎么能在 html 本身中使用印度格式。
我已经使用过滤器以印度格式显示值,这对于查看数据很有效,但我也想在输入期间做同样的事情,但是当我尝试在模型中使用相同的过滤器时它没有显示任何东西。
html:
<input ng-if="vm.farmer.type === 'Advance'"
type="number" maxlength="9" placeholder="{{'advamount_message' | translate}}" step=".01"
ng-model="vm.advance.amount_out" ng-change="vm.fillStarted()"
next-focus id="field1"
field-to-validate="yes"
field-value="{{vm.advance.amount_out}}" field-validation-type="num" field-name="{{'vamount_message' | translate}}">
用于查看的过滤器:
.filter('INR', function () {
return function (input) {
if (!isNaN(input)) {
//var currencySymbol = '₹';
/*var result = input.toString().split('.');
var lastThree = result[0].substring(result[0].length - 3);
var otherNumbers = result[0].substring(0, result[0].length - 3);
if (otherNumbers !== '') {
lastThree = ',' + lastThree;
}
var output = otherNumbers.replace(/\B(?=(\d{2})+(?!\d))/g, ',') + lastThree;
// var output = otherNumbers.replace(/(\d)(?=(\d\d)+\d$)/g, ',') + lastThree;
if (result.length > 1) {
output += '.' + result[1];
}
return output;*/
var negative = input < 0;
var str = negative ? String(-input) : String(input);
var arr = [];
var i = str.indexOf('.');
if (i === -1) {
i = str.length;
} else {
for (var j = str.length - 1; j > i; j--) {
arr.push(str[j]);
}
arr.push('.');
}
i--;
for (var n = 0; i >= 0; i--, n++) {
if (n > 2 && (n % 2 === 1)) {
arr.push(',');
}
arr.push(str[i]);
}
if (negative) {
arr.push('-');
}
return arr.reverse().join('');
}
};
观看期间:
{{vm.farmer.balance | INR}}