angularjsangularjs-ng-change

ng-change event should be called only after typing is completed


I have a text field with ng-change event.Event should be called only when the user completed typing.How to delay calling the event?

<input type="text" ng-model="custname" ng-change="findCustName()">

Solution

  • You should use ng-blur instead

    A blur event fires when an element has lost focus.

    <input type="text" ng-model="custname" ng-blur="findCustName()">
    

    If you do not want to use ng-blur or lost focus, you can use the same ng-change with ng-model-options

    As of Angular 1.3, you could use Angular ng-model-options directive

    <input ng-change="findCustName()" ng-model-options="{debounce:1000}">