1
<input name="maxSalary" id="MaxSalary" type="number" min="0" class="form-control" ng-model="dp.maximumSalary" ng-change="minMaxSalaryComparision()" />

this is my html input. when I add a integer value, its work properly. but if I add 0000 ng-change only fire with first entered 0. this is my java script.

 $scope.minMaxSalaryComparision = function () {
        alert($scope.dp.maximumSalary);
    };

any idea?

2
  • thats because 0 and 00 and interpreted as same. So in dirty checking, the value is just still the same no matter how many zeros you add. You can use keypress event if you want to check for this scenario. Commented Mar 29, 2017 at 5:28
  • Actually it consider 0 and 00000 is same value. Because you select type is number. If you want to differentiate then you need to change type to text Commented Mar 29, 2017 at 5:30

2 Answers 2

1

Use ng-keyup or ng-keydown instead of ng-change

<input name="maxSalary" id="MaxSalary" type="number" min="0" class="form-control" ng-model="dp.maximumSalary" ng-keyup="minMaxSalaryComparision()" />

DEMO

angular.module("Demoapp",[])
.controller("Democtrl",function($scope){

 $scope.minMaxSalaryComparision = function () {
        alert($scope.dp.maximumSalary);
    };
})
	<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.min.js"></script>
<div ng-app="Demoapp" ng-controller="Democtrl">
 <input  min="0" class="form-control" ng-model="dp.maximumSalary" ng-keyup="minMaxSalaryComparision()" />

</div>

Sign up to request clarification or add additional context in comments.

Comments

1

ng change fires when you change the value of the ng model. since 0000 is equal to 0 ng change does not getting fired.

alternatively can use ngKeyup to fire this event when key released

angular.module("app",[])
.controller("ctrl",function($scope){

 $scope.minMaxSalaryComparision = function () {
        alert($scope.dp.maximumSalary);
    };
})
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<div ng-app="app" ng-controller="ctrl">
 <input name="maxSalary" id="MaxSalary" type="number" min="0" class="form-control" ng-model="dp.maximumSalary" ng-keyup="minMaxSalaryComparision()" />

</div>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.