Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AngularJS ngChange trigger onblur

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.

like image 482
9blue Avatar asked Oct 18 '13 18:10

9blue


People also ask

What is Ng blur in AngularJS?

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.

What is Ngchange in angular?

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.

What is ngInit?

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.

What is Ngmodeloptions in angular?

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.


2 Answers

Use ng-model-options

$scope.onchange = function () {} 
<input type="text" ng-model="x" ng-change="onchange()" ng-model-options="{updateOn: 'blur'}"/> 
like image 67
Niels Steenbeek Avatar answered Oct 05 '22 02:10

Niels Steenbeek


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'; } 
like image 39
Jason Avatar answered Oct 05 '22 02:10

Jason