2016-10-06 129 views
0

如何在AngularJS中通過貨幣過濾器中的'逗號'默認爲'點'來更改小數點?在AngularJS中替換圓點和逗號

例子:

{{10000 | currency}} 10,000.00 ==> 10.000,00 

謝謝!

+0

也許https://developer.mozilla.org/en-US/docs/Web/JavaScript/參考/ Global_Objects /編號/ toLocaleString – epascarello

+2

http://stackoverflow.com/questions/27547680/angular-js-currency-symbol-euro-after - 只是谷歌搜索「角度currrency歐洲」 –

回答

1

這是一個工作演示,使用修飾器在配置塊中修改語言環境NUMBER_FORMATS屬性DECIMAL_SEPGROUP_SEP。這就是所謂的只有一次,有效期爲依賴於它的任何filter

angular 
 
    .module('App', []) 
 
    .config(['$provide', function($provide) { 
 
     $provide.decorator('$locale', ['$delegate', function($delegate) { 
 
      $delegate.NUMBER_FORMATS.DECIMAL_SEP = ','; 
 
      $delegate.NUMBER_FORMATS.GROUP_SEP = '.'; 
 
      return $delegate; 
 
     }]); 
 
    }]) 
 
    .controller('ExampleController', function($scope) { 
 
     $scope.myNumber = 10000; 
 
    });
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script> 
 

 
<div ng-app="App" ng-controller="ExampleController"> 
 
    <p>{{myNumber | currency}}</p> 
 
</div>