I have searched everywhere for this. Every stack overflow that has an answer, it does not actually work. Same with any examples or google group examples from for angular including the docs.
Seems simple. I want a function to get called on an input for each key pressed by the user.
simple input with a ng-model
<input class="form-control" ng-model="model.thisisnotfun" formatter type="text" required>
According to everything i read. $formatters should update the value from the model to the view calling any functions in the $formatters array. They never get called when i type in the input box.
.directive('formatter', function ($filter, $parse) {
return {
require: 'ngModel',
link: function (scope, element, attrs, ngModel) {
ngModel.$formatters.push(
function (value) {
console.log('this only gets called on page load');
}
);
}
};
})
I know there are plenty of custom ways to do this, which i have already done. I do not need a work around, i just want to know how to use $formatters correctly to "format" the view data.
very very simple jsfiddle http://jsfiddle.net/fh7sB/4/
Thanks for any help.
$formatterin AngularJS documentation. Could you help me with it?