Search code examples
ajaxangularjstimeoutdelay

AngularJS timeout AJAX call


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)


Solution

  • 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 
        }
    }