Angular 1.4.x numeric field with gettersetter not working for decimal numbers

I have a problem in chrome (47), where when using type type input in combination with ng-model-options = "{getterSetter: true}" it does not allow you to enter decimal numbers in the field.

With getterSetter: (doesn't work)

<input ng-model="amount" ng-model-options="{ getterSetter: true }" step="0.01" type="number" > 

Without getterSetter: (works)

 <input ng-model="_amount" step="0.01" type="number"> 

see demo plunker http://plnkr.co/edit/qu8UXCUtkJaFwjgGE1NX?p=preview

+5
source share
1 answer

What happens when you declare a getterSetter function, this function is called every time you change the input value.

So, when you write "12.", the function is called, but it is not a real number, so it takes out the ".". to provide a valid value.

Try typing “123,” and then add “.”. between numbers like "12.3" that works!

Edit

I fixed my code, now it works.

Try the following:

  $scope.amount = function(newValue) { return arguments.length ? ($scope._amount = newValue) : $scope._amount; }; 

Here is a forked plunkr: http://plnkr.co/edit/xZtZLH5He4ZnjkqhFApY?p=preview

+1
source

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


All Articles