Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Angularjs static number filter with custom delimiter

How to change delimiter in Angularjs number filter from comma to something custom?

Now {{ price | number }} returns 1,000.00. And I need to have it like 1 000.00.

How exactly do I need to rewrite built-in angular filter?

like image 440
Alliswell Avatar asked Aug 04 '15 12:08

Alliswell


Video Answer


1 Answers

You don't have to mess with Angular source or change locale to other. You don't even need to write custom filter for this. just change NUMBER_FORMATS.GROUP_SEP of the $locale service to whatever you need:

$locale.NUMBER_FORMATS.GROUP_SEP = ' ';
$scope.price = 100000;

But it's better to do it in run block, rather then in controller.

angular.module('demo', []).controller('MainCtrl', function($scope, $locale) {
    $locale.NUMBER_FORMATS.GROUP_SEP = ' ';
    $scope.price = 100000;
});
<script src="https://code.angularjs.org/1.4.3/angular.js"></script>

<div ng-app="demo" ng-controller="MainCtrl">
    {{ price | number }}    
</div>
like image 159
dfsq Avatar answered Oct 24 '22 06:10

dfsq