Show float field in currency format using filters in AngularJS

1

I'm working with AngularJS and to show the user a field using a comma, I'm unfortunately forced to make a replace on the point.

I wonder if there are any filter or directive to solve the case. In my code, I need a float field to continue so it can be sent to webservice , but for the user, a currency field is separated by a comma, not by a dot.

    
asked by anonymous 20.01.2016 / 14:35

2 answers

1

More specifically:

{{ Valor | currency:'BRL':2 }}

To bring the comma, change your app.module too:

import { NgModule, LOCALE_ID } from '@angular/core';

.
.
.
@NgModule({
  ...
  providers: [
      ...
      { provide: LOCALE_ID, useValue: "pt-BR" },
      ...
  ],
  ...
})
    
27.09.2017 / 15:30
1

You can do the formatting directly in the view, without having to manipulate the value through a filter or directive custom. Example:

$scope.meuValor = 10.3

<p>Valor: {{meuValor | currency}}</p>

If automatic conversion is not done (added R $), you can still set display options, as documentation here , such as the monetary acronym and number of houses after the comma.

{{campo | currency:sigla:casas}}
{{campo | currency:'R$':2}}

See an example: link

Edited:

I had forgotten the . in the decimal separator. This can be solved by using a locale file, like this: link

Just load this file into the index, or whatever you want. I, for example, concatenate it with other function files by mounting a module that I load as a dependency on module master.

    
20.01.2016 / 14:45