Skip to content

Instantly share code, notes, and snippets.

@goldalworming
Created July 14, 2014 03:38
Show Gist options
  • Save goldalworming/bb389c9ac7f163858e06 to your computer and use it in GitHub Desktop.
Save goldalworming/bb389c9ac7f163858e06 to your computer and use it in GitHub Desktop.
var timeoutPromise;
var delayInMs = 2000;
$scope.$watch("query", function () {
$timeout.cancel(timeoutPromise); //does nothing, if timeout alrdy done
timeoutPromise = $timeout(function(){ //Set timeout
$scope.loading = true;
returnFactory.query($scope.query).then(function (returns) {
$scope.returns = returns;
$scope.loading = false;
});
},delayInMs);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment