Skip to content

Instantly share code, notes, and snippets.

@travist
Last active October 2, 2021 11:28
Show Gist options
  • Select an option

  • Save travist/057e613adbcd31510d6e110786d88e10 to your computer and use it in GitHub Desktop.

Select an option

Save travist/057e613adbcd31510d6e110786d88e10 to your computer and use it in GitHub Desktop.
How to debounce a $scope.$watch for Angular.js.
['$scope', function($scope) {
var debounceTimer = null;
var debounce = function(cb) {
if (debounceTimer) clearTimeout(debounceTimer);
debounceTimer = setTimeout(cb, 200);
};
$scope.$watch('submission.data', function(data) {
debounce(function() {
// Put your logic here...
});
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment