When the value of an input does not meet a certain condition, I need to change it. In this example, if the unit price input is changed to a non-numeric value when adding a Detail, I want to set the value to "0.00".
scope.$watch(attrs.ngModel, function(newValue, oldValue) {
if ( isNaN(newValue) ) {
scope.item.price = "0.00";
console.log("isn't numeric");
} else {
console.log("is numeric");
}
});
The issue arises when changing the value of "scope.item.price", causing both "isn't numeric" and "is numeric" messages to be printed. Is there a way to change the input value without triggering scope.$watch twice?