2017-01-15 89 views

回答

0

您無法通過貨幣過濾器來實現。只需使用數字過濾器。

<div ng-controller="MyCtrl"> 
      <input class="tb" ng-model="numberInput" type="text" />   {{ "₹ "+(numberInput | number:2) }}    
    </div> 

DEMO

var app = angular.module("app", []); 
 
app.controller('AddSiteURLCntr', function($scope, $sce) { 
 
    $scope.numberInput = '1275.23'; 
 
    
 
})
<!DOCTYPE html> 
 
<html> 
 

 
<head> 
 
    <script data-require="[email protected]" 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>

0

你可以試試這個

查看

<span ng-bind="getCurrency(cart.getTotalPrice())"></span>&nbsp; 
<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); 
    } 
0

<!DOCTYPE html> 
 
<html> 
 
<head> 
 
\t <title></title> 
 
\t <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"> 
 
\t <input type="number" name="price" ng-model="totalPrice"> 
 
\t <p>{{getTotalPrice() | currency : "&#8377; "}}</p> 
 
</div> 
 
<script type="text/javascript"> 
 
\t var app = angular.module("my-app",[]); 
 
\t app.controller("my-controller",function($scope){ 
 
\t \t $scope.totalPrice = 0; 
 
\t \t $scope.getTotalPrice = function(){ 
 
\t \t \t return $scope.totalPrice; 
 
\t \t } 
 
\t }); 
 

 
</script> 
 
</body> 
 
</html>

+0

您可以使用過濾器實現這一目標。查看我發佈的代碼。 –

0

只要把空間符號之後,類似這樣的

HTML - {{cart.getTotalPrice()|貨幣:「₹」}}

,你會得到你想要的輸出...