Place "R $" in angular

3

I need to put an R $ in AngularJs. The code is this, someone could help me and is returning a value in the value.

$scope.addValue = function(el) {
    var element = el.currentTarget.attributes["ng-model"].nodeValue;
    var status = el.currentTarget.checked;
    if (status == true) {
        $scope.formData.saldoItensSelecionados = Number($scope.formData.saldoItensSelecionados) + Number(scope["resultSimulacao"]["tipsaa1VO"][element]);
    } else {
        $scope.formData.saldoItensSelecionados = Number($scope.formData.saldoItensSelecionados) - Number(scope["resultSimulacao"]["tipsaa1VO"][element]);
    }
}
    
asked by anonymous 18.11.2015 / 19:02

2 answers

7

You can make this view directly in your view through the code:

{{meuvalor | currency: 'R$'}}

This code would be used the moment it is displayed. He himself will take care of leaving its value in currency format. For example, if your $scope looks like this:

$scope.meuvalor = 10;

The display will be: R$10,00

Answering the second question, posted in the comments:

this way:

<input type="text" name="meuvalor" ng-model="meuvalor" />

However, the NOT input will get the R$ value, only the 10 numeric. In order for it to also have the R $, you must use some mask service or a directive to manipulate the prefix.

If you do this, be careful because you can save the data in a way that will not be recognizable by the structure I gave you above.

    
18.11.2015 / 19:10
0

According to the official angular documentation, session i18n and l10n :

  

Angular supports i18n / l10n for date , number and    currency filters. All locatable Angular components depend on   locale-specific rule sets managed by the $ locale service .

     

There are a few examples that showcase how to use Angular filters with   various locale rule sets in the i18n / e2e directory of the Angular   source code.
  Angular separates number and datetime format rule sets into different files, each file for a particular locale. You can find a list of currently supported locales here .

Then:

<html ng-app>
 <head>
….
   <script src="angular.js"></script>
   <script src="i18n/angular-locale_pr-br.js"></script>

   <script>{{ 1000 | currency }}</script>
 </head>
</html>
    
18.11.2015 / 21:49