AngularJS - Blur binding 1.2.0-rc.2
by Aaronias
HTML
<script src="http://code.angularjs.org/1.2.0-rc.2/angular.js"></script>
AngularJS 1.2.0-rc.2
<input type="text" ng-model="value" ng-model-onblur>
{{value}}
JavaScript
function Main() {}
// override the default input to update on blur
angular.module('app', []).directive('ngModelOnblur', function() {
return {
restrict: 'A',
require: 'ngModel',
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());
});
});
}
};
});