>>>> function bind() { >>>> return ngModel.$formatters.unshift(function (value) { >>>> return format(value); >>>> }); >>>> }Don't know why the priority approach didn't work but this shows that your formatter needs to be first in the $formatters array.....
app.directive('smNumberFormat', ['$filter', function ($filter) { return { restrict: 'A', // only activate on element attribute require: '?ngModel', // get a hold of NgModelController priority: 100, link: { pre: function (scope, element, attrs, ngModel) { if (!ngModel) return; // do nothing if no ng-model //Set the default decimal place to zero, if accuracy is not specified var accuracy = parseInt(attrs.accuracy) || 0; var stripCommas = attrs.stripCommas || true; ngModel.$render = function () { return element.val(ngModel.$viewValue); }; var format = function (newValue) { console.log("Running snNumberFormat formatter"); if (accuracy > 0) { newValue = parseFloat(newValue); } else { newValue = parseInt(newValue); } //Let's not show any value if it's zero or not a number, so the placeholder text is displayed instead if (isNaN(newValue)) return undefined; newValue = $filter('number')(newValue, accuracy); if (stripCommas) { newValue = newValue.split(",").join(""); } return newValue; }; function bind() { return ngModel.$formatters.push(function (value) { return format(value); }); } bind(); element.on('blur', function () { return element.val(format(ngModel.$viewValue)); }); }}BTW, would you agree that for numberInput we probably don't need to check for actual number, we may just check for the value (could be a string) being a number. If that code would have checked that instead of isNumber function, then I would not have a problem.