molerat molerat - 2 months ago 25
AngularJS Question

AngularJS number filter greater than 1000

In Angular I have this line

<input type="number" value="{{ price.fare + price.tax | number:2 }}" />


But as soon as
price.fare
and
price.tax
add up to
1000
, I get this error:

The specified value "1,000.00" is not a valid number. The value must match to the following regular expression: -?(\d+|\d+\.\d+|\.\d+)([eE][-+]?\d+)?


How can I fix this?

Answer

Remove type=number in total column. Plunker here - https://plnkr.co/edit/7cY2Lm?p=preview

  <div ng-controller="myController as price">
      <h1>AngularJS number filter greater than 1000</h1>
      <a href="http://stackoverflow.com/questions/36118671/angularjs-number-filter-greater-than-1000">Stack Overflow </a>
      <br/>
      Fare: <input type="number" ng-model="price.fare" />
      <br/>
      Tax: <input type="number" ng-model="price.tax" />
      <br/>
      Total: <input value="{{ price.fare + price.tax | number:2 }}" />
      <br/>
    </div>

Controller:

myApp.controller('myController', function($scope) {
  this.fare = 990;
  this.tax = 20;
});