If I have an input such as below. What is the cleanest way I can ensure the empty string (input) is always 0.00.
I was thinking it could be done with a watch but was wondering if there would be an easier way built into angular or html5 to handle it.
<input class="form-control" type="number" step="0.01" placeholder="$"
data-ng-model="status.approved.price" />
Edit: What I actually needed was blur which handles clicking out of input as well as tabbing out. Tomek Sułkowski helped me get to this solution as you can see in this directive. Once the user leaves the input it will default to 0 if there is no value.
return {
restrict: 'A',
require: 'ngModel',
link: function (scope, elem, attrs, ngModelCtrl) {
elem.on('blur', function() {
if (!elem.val()) {
elem.val('0');
ngModelCtrl.$setViewValue('0');
}
});
}
};