0

I want to use the onSelect event for my select tag instead of ng-change event.

I face some issue by using ng-change event on my code while I using update the onChange Function call automatically on set value in my update page and I have some calculation in that function so the calculation gets call automatically and many things connected with one function.

so I want to call function only when I select any value from select box please response if you have a proper good solution.

Talha
  • 903
  • 8
  • 31
Nikunj
  • 86
  • 11

1 Answers1

4

You need to add Directive in your Input Tag.

If you add the directive to your code you would change your binding to this:

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

Here is the directive:

// override the default input to update on blur

angular.module('app', []).directive('ngModelOnblur', function() {
    return {
        restrict: 'A',
        require: 'ngModel',
        priority: 1, // needed for 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());
                });         
            });
        }
    };
});

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

Community
  • 1
  • 1
sagar chopada
  • 332
  • 1
  • 11