AngularJS数字过滤器大于1000

时间:2016-03-20 19:48:01

标签: angularjs html5

在Angular中我有这一行

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

但是只要price.fareprice.tax加起来1000,我就会收到此错误:

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+)?

我该如何解决这个问题?

3 个答案:

答案 0 :(得分:4)

在总列中删除type = number。 Plunker在这里 - 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>

控制器:

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

答案 1 :(得分:4)

解决了类似类型的错误&#39;指定值&#34; xxxx&#34;不是有效的数字。该值必须与以下正则表达式匹配: - ?(\ d + | \ d +。\ d + + |。\ d +)([eE] [ - +]?\ d +)?&#39;在html标记中将替换为 ng-value

答案 2 :(得分:0)

感谢您的回复。我提出了以下解决方案,它按照我需要的方式工作:

#include "Random.hpp"
#include <time.h>
std::default_random_engine Random::gen;
std::uniform_int_distribution<int> Random::ints;
void Random::seed()
{
    gen.seed(static_cast<unsigned int>(time(NULL)));
}
int Random::getRandom(int minInclusive, int maxInclusive)
{
    std::uniform_int_distribution<int>::param_type range(minInclusive, maxInclusive);
    ints.param(range);
    return ints(gen);
}