Numeric input in steps of 0.01 gives undefined for certain values ​​in angular

When entering this type in angular (1.6.1), the value is undefinedfor values ​​from 9.03to 9.05inclusive. The problem is reproduced with other values, among others 9.62, 9.63, 17.31.

<input type="number" step="0.01" data-ng-model="$ctrl.numericValue" />

This fiddle reproduces the problem. Just click on the numeric input.

Tested on firefox and chromium under linux mint 18.

It seems to be associated with an attribute "step". If it is set to "0.001", there is no problem. But I am threatening money in this application, so 2 decimal numbers are required.

Note: if the value is initially set to 9.03through data-numeric-value, it is not undefined.

Any workaround for this error?

change

updated fiddle to show whit behavior step="0.01"compared tostep="0.001"

edit 2 I did plunkr when filling out the error report to find out that the error was fixed in the snapshot version, because it is 1.6.2. But this version is not available for download through the angularjs site at the moment.

+6
source share
3 answers

This seems to be a bug in Angular. Using Angular 1.6.0, this problem occurs. If you use Angular 1.5.9, it works fine. Something between the two versions caused this problem, and it has not yet been found or resolved in 1.6.1.

So, the best way to do this is to raise an error with the Angular team.

, , Angular 1.5.9.

Windows 7 Firefox Chrome, .

+3

- JavaScript. , ( , 1), , 100.

0

, jquery. jquery angular:

 <script
    src="https://code.jquery.com/jquery-3.1.1.js"
    integrity="sha256-16cdPddA6VdVInumRGo6IbivbERE8p7CQR3HzTBuELA="
    crossorigin="anonymous"></script>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.1/angular.min.js"></script>

<input id="numericValue1" type="number" step="0.01" ng-model="$ctrl.numericValue1" />

,

ctrl.showValue1 = function(){
    return "value 1 is " + $('#numericValue1').val() + " and its type is " + typeof ctrl.numericValue1;
  };

, !

-1

Source: https://habr.com/ru/post/1013989/


All Articles