Put Dollar " R$ " in angular

Asked

Viewed 1,114 times

3

I need to put a R$ in Angularjs. The Code is this, someone could help me and is returning a value in 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]);
    }
}

2 answers

7


You can make this view directly in your view via code:

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

This code would be to be used at the time it is displayed. It will take care to leave its value in currency format. For example, if your $scope be like this:

$scope.meuvalor = 10;

The exhibition will be: R$10,00


Answering the second question, posted in the comments:

thus:

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

However, the input NAY will receive the value R$, only the numeral 10. In order to also have the R$, you must use some mask service or a Directive to manipulate the prefix.

If you do this, be careful, for you can save the die in a way that will not be recognizable by the structure I passed you above.

  • Vlw Cara Helped a lot, Plus I have a problem yet the main input does not receive angular Expression {{}} only gets ng-model as I could do it ?

  • I edited the answer to answer that. It’s clear now?

0

According to the official documentation of the corner, session i18n and l10n:

Angular Supports i18n/l10n for date, number and currency Filters. All localizable Angular Components Depend on locale-specific Rule sets Managed by the $locale service.

There 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.

So:

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

   <script>{{ 1000 | currency }}</script>
 </head>
</html>

Browser other questions tagged

You are not signed in. Login or sign up in order to post.