javascript - Angular.js formatter not being fired on modelValue change -


http://plnkr.co/edit/hn1pbgrsk6xqt9pwxcky?p=preview should quite self explaining

ctrl.$formatters runs when set model value, don't after update it.

according have $formatters called when view first populated? should fire everytime model value changed, what's wrong? thanks.

use natural model setter, scope[attrs.ngmodel] instead of setviewvalue.

app.directive('format', function($filter) {   return {     require: 'ngmodel',     link: function(scope, element, attrs, ctrl) {     element.unbind('input').unbind('keydown').unbind('change');         element.bind('blur', function() {             if (element.val()) {                 scope.$apply(function() {                     scope[attrs.ngmodel] = element.val();                 });                      }         });          ctrl.$formatters.unshift(function(modelvalue) {             if (modelvalue) {                 var formatted = $filter('currency')(modelvalue);                 return formatted;             }         });     } } }); 

you need parser work correctly.


Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -