Goce Ribeski Goce Ribeski - 2 months ago 7x
Ajax Question

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


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)


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

Example :

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

          /* Execute your script */

        }, 1000); //add timeout