Problem: Input type number with min, max is not working while typing in input box we can type less/more than min, max value. (but by the arrow of input type number it is working fine.)
Requirement: restrict to enter the value in input type number that not in range of min and max
"Using Angular.js want to solve this problem without an extra directive and without changing the input type number to text." Plunker
ng-keyup: unable to do event.preventDefault() why? This is why we can type more/less than min or max value. I am getting the correct value while changing.
ng-keypress: lagging behind 1 value. So the first value is undefined (this is a problem for my question). I am able to to do event.preventDefault();
Shold be: ng-keyup with event.preventDefault(); or ng-keypress with correct order
var app = angular.module('myApp', []);
app.controller('myCtrl', function($scope, $timeout) {
$scope.myScore;
$scope.limit = function(event, myScore){
console.log(event, $scope.myScore, myScore);
// do your code here myScore should be between (min-max)
event.preventDefault();
}
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.5.11/angular.min.js"></script>
<div ng-app="myApp" ng-controller="myCtrl">
<!-- <input type="number" ng-model="myScore" min="0" max="200" ng-keypress="limit($event, myScore)"> -->
<input type="number" ng-model="myScore" min="0" max="200" ng-keyup="limit($event, myScore)">
{{myScore}}
</div>