I have the an input field where only positive numbers are allowed.
<input id="charge-hours" type="text" class="charge-position-hours-edit" placeholder="0" ng-model="charge.hours">
How to control the setting of ng-model.
I would like write a precondition before the value set in the scope. Something like
$scope.precondition = function (value) {
if (!isNan(value)) {
$scope.value=value;
}else{
//do nothing
}
}
Is this possible in javascript/angularjs? In jave there would be setter for that.
EDIT
My Question was not clear enough.
I really want only positive numbers are typable in the input field, and only positive numbers should be bound to the ng model of angularjs.
Is there a way to save the oldValue if I use ng change? Then I may write something like
if (condition===true) //ok
else $scope.value=oldValue;