for ng-Change
, is there way to trigger it only when on blur
? Similar to jquery on('change')
?
I am seeking for a pure angular
way of doing this.
The ng-blur directive tells AngularJS what to do when an HTML element loses focus. The ng-blur directive from AngularJS will not override the element's original onblur event, both the ng-blur expression and the original onblur event will be executed.
The ng-change directive tells AngularJS what to do when the value of an HTML element changes. The ng-change directive requires a ng-model directive to be present.
The ngInit directive allows you to evaluate an expression in the current scope. This directive can be abused to add unnecessary amounts of logic into your templates. There are only a few appropriate uses of ngInit : aliasing special properties of ngRepeat , as seen in the demo below.
The ng-model-options directive is used to control the binding of an HTML form element and a variable in the scope. You can specify that the binding should wait for a specific event to occur, or wait a specific number of milliseconds, and more, see the legal values listed in the parameter values below.
Use ng-model-options
$scope.onchange = function () {}
<input type="text" ng-model="x" ng-change="onchange()" ng-model-options="{updateOn: 'blur'}"/>
Starting with release 1.2.0rc1 there is an ng-blur
directive
jsfiddle: http://jsfiddle.net/9mvt8/6/
HTML:
<div ng-controller="MyCtrl"> <input type='text' ng-blur='blurCount = blurCount + 1'/> <input type='text' ng-blur='blurCount = blurCount + 1' /> blur count: {{blurCount}} </div>
Script:
function MyCtrl($scope) { $scope.blurCount = 0; $scope.name = 'Superhero'; }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With