Format monetary value with AngularJS

0

I'm getting the following values

<h3 id="valor">Valor Mensalidade: R${{curso_se.preco_curso}}</h3>       
<h1 style="color:green;">PrimeiraMensalidade:R${{curso_se.preco_matricula}}</h1>

But they are coming with dot and without separating houses from thousands, for example example: 2.432,00

I tried to give replace but it did not work

$("#valor").val(replace(".", ","));
    
asked by anonymous 20.12.2017 / 18:23

1 answer

3

Please do not do this kind of gambiarra. Do it the right way.

Add the script angular-locale to the location you intend to use (usei pt -br in the example) and then use the filter currency .

angular.module('app', []).controller('mainCtrl', function($scope) {
  $scope.preco_matricula = 1150.50 ;
});
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script><scriptsrc="https://cdnjs.cloudflare.com/ajax/libs/angular-i18n/1.6.7/angular-locale_pt-br.js"></script>

<div ng-app="app" ng-controller="mainCtrl">
  <h1>PrimeiraMensalidade: {{ preco_matricula | currency }}</h1>
</div>
    
20.12.2017 / 18:30