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

5.4k Views Asked by At

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()">
3

There are 3 best solutions below

10
Sajeetharan On BEST ANSWER

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}">
1
IsraGab On

When I want to call a function when typing is completed I use ng-keyup.

Using ng-keyup your function will be call every time user press a key.

I know your asking when user finish typing , but let me explain why I prefer using ng-keyup and not ng-blur

If I have to call a validation function, ng-blur won't help, because you will have to focus out to launch the function. Using ng-keydown, function will be launch. so if user finished typing it will be launch also

0
Amirio On

i use this for call function after typing new value done.

ng-model-options="{ updateOn: 'blur' }" watch-selection