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.

1 Answer 1

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

Sign up to request clarification or add additional context in comments.

1 Comment

thanks Sir for your reply,the error has gone but the ng-change doesn't work now :/

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.