1

On next example I modified event, so instead on button click now call is on-change:

<input type="text" ng-model="keywords" ng-change="search()"/>

a-simple-search-with-angularjs-and-php

How to add delay/timeout so the script waits a second before making AJAX call? (i.e. to give the user time to finish typing before making call)

2 Answers 2

1

Try to add the function $timeout in your search scope.

Example :

function Ctrl($scope, $timeout) {
    $scope.search = function() {
        $timeout(function(){

          /* Execute your script */

        }, 1000); //add timeout 
    }
}
Sign up to request clarification or add additional context in comments.

1 Comment

Did not worked as this: /* Execute your script */ alert('test');
0

Angular 1.3, just add a debounce option on the model

<input type="text" ng-model="keywords" ng-model-options="{debounce: 1000}">

Documentation on ngModelOptions:

https://docs.angularjs.org/api/ng/directive/ngModelOptions

Comments

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.