如何在“₹”之后添加空格/特殊字符。
预期产出:₹49
当前输出:₹49
HTML - {{cart.getTotalPrice()|货币: “₹”}}
答案 0 :(得分:0)
使用货币过滤器无法实现。只需使用数字过滤器。
<div ng-controller="MyCtrl">
<input class="tb" ng-model="numberInput" type="text" /> {{ "₹ "+(numberInput | number:2) }}
</div>
<强>样本强>
var app = angular.module("app", []);
app.controller('AddSiteURLCntr', function($scope, $sce) {
$scope.numberInput = '1275.23';
})
<!DOCTYPE html>
<html>
<head>
<script data-require="angular.js@1.4.7" data-semver="1.4.7" src="https://code.angularjs.org/1.4.7/angular.js"></script>
<link rel="stylesheet" href="style.css" />
<script src="script.js"></script>
</head>
<body ng-app='app'>
<div ng-controller="AddSiteURLCntr">
<input class="tb" ng-model="numberInput" type="text" /> {{ "₹ "+(numberInput | number:2) }}
</div>
</body>
</html>
答案 1 :(得分:0)
你可以试试这个
查看强>
<span ng-bind="getCurrency(cart.getTotalPrice())"></span>
<span ng-bind="getElem(cart.getTotalPrice())"></span>
<强>控制器强>
$scope.getCurrency = function (item) {
return ($filter('currency')(item,'₹')).substring(0,1);
}
$scope.getElem = function (item) {
return ($filter('currency')(item,'₹')).substring(1,item.length);
}
答案 2 :(得分:0)
<!DOCTYPE html>
<html>
<head>
<title></title>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.1/angular.min.js"></script>
</head>
<body ng-app="my-app">
<div ng-controller="my-controller">
<input type="number" name="price" ng-model="totalPrice">
<p>{{getTotalPrice() | currency : "₹ "}}</p>
</div>
<script type="text/javascript">
var app = angular.module("my-app",[]);
app.controller("my-controller",function($scope){
$scope.totalPrice = 0;
$scope.getTotalPrice = function(){
return $scope.totalPrice;
}
});
</script>
</body>
</html>
答案 3 :(得分:0)
只需在符号后放一个空格,就像这样
HTML - {{cart.getTotalPrice()|货币:“₹”}}
你会得到你想要的输出......
答案 4 :(得分:0)
您可以扩展货币过滤器,以创建自己的过滤器...
angular.module('yourModuleName').filter('money', filter);
function filter($filter, $locale) {
const formats = $locale.NUMBER_FORMATS;
return function(amount, currencySymbol) {
if (!currencySymbol) currencySymbol = formats.CURRENCY_SYM + ' ';
return $filter('currency')(amount, currencySymbol);
};
}
现在,您可以应用名为“ money”的新过滤器了...
<span>{{vm.contractedPrice | money}}</span>