Goce Ribeski Goce Ribeski - 1 year ago 166
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)

Answer Source

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

Example :

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

          /* Execute your script */

        }, 1000); //add timeout 
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download