How to put mask on table with angular?

Asked

Viewed 2,361 times

3

How to put monetary mask in a table ? For inputs I used the directive ui-money-Mask, but I need to put in a table cell.

<td>{{item.valor}}</td>

1 answer

2


Use the filter currency

To show in real format (R$) you have two options, using the Angular Locale, see Using Locale in Angularjs

<!--Utilizando o Angular Locale-->
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.1/angular.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.2.1/i18n/angular-locale_pt-br.js"></script>

<div ng-app ng-init="valor='85.41'">
  <input ng-model="valor" />
  <!--Máscara default utilizando o locale - (R$xx,xx).-->
  <p>{{valor | currency}}</p>
  <!--Você pode alterar o símbolo da moeda como preferir - (R$ xx,xx).-->
  <p>{{valor | currency:'R$ '}}</p>
</div>

Or you can enter an identifier in the filter, so it will only show the identifier you enter (R$ for example), but in this way (without using the locale) the decimal separator will be the English standard with a dot and not a comma as in the Brazilian format.

<!--Sem o Angular locale-->
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.1/angular.min.js"></script>

<div ng-app ng-init="valor='85.41'">
  <input ng-model="valor" />
  <!--Máscara Default sem o locale - ($xx.xx).-->
  <p>{{ valor | currency }}</p>
  <!--Máscara formatada sem o locale - (R$xx.xx).-->
  <p>{{ valor | currency: 'R$' }}
</div>

  • This already helps me, but to print in R$ xxx,xx format, how do I ? In this case, using comma instead of dot ?

  • 1

    The archive angular-locale is a JSON, you can find in the file where you define the currency and add a space R$ or add the mask with the space directly on filter:currency

  • Dude, it was worth the help.

Browser other questions tagged

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