Angularjs: input[text] ngChange fires while the value is changing -


ngchange firing while value changing (ngchange not similiar classic onchange event). how can bind classic onchange event angularjs, fire when contents commited?

current binding:

<input type="text" ng-model="name" ng-change="update()" /> 

this post shows example of directive delays model changes input until blur event fires.

here fiddle shows ng-change working new ng-model-on-blur directive. note slight tweak original fiddle.

if add directive code change binding this:

<input type="text" ng-model="name" ng-model-onblur ng-change="update()" /> 

here directive:

// override default input update on blur angular.module('app', []).directive('ngmodelonblur', function() {     return {         restrict: 'a',         require: 'ngmodel',         priority: 1, // needed angular 1.2.x         link: function(scope, elm, attr, ngmodelctrl) {             if (attr.type === 'radio' || attr.type === 'checkbox') return;              elm.unbind('input').unbind('keydown').unbind('change');             elm.bind('blur', function() {                 scope.$apply(function() {                     ngmodelctrl.$setviewvalue(elm.val());                 });                      });         }     }; }); 

note: @wjin mentions in comments below feature supported directly in angular 1.3 (currently in beta) via ngmodeloptions. see the docs more info.


Comments

Popular posts from this blog

html - How to style widget with post count different than without post count -

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

javascript - storing input from prompt in array and displaying the array -