I\'m trying to write a directive that automatically formats a number in the but the the model isn\'t formatted.
Getting it to work is fine, on lo
Small edit to Maxim Shoustin's answer below as per the answer to this question: AngularJS formatter - how to display blank instead of zero
Only change is to ensure that the input is blank rather than zero on the deletion of the last number:
ctrl.$parsers.unshift(function (viewValue) {
console.log(viewValue);
if(viewValue){
var plainNumber = viewValue.replace(/[^\d|\-+|\.+]/g, '');
elem.val($filter('number')(plainNumber));
return plainNumber;
}else{
return '';
}
});
http://jsfiddle.net/2n73j6rb/