javascript - debounce not firing inside $scope.$watch -


this question has answer here:

i'm trying run function when model variable updates in ui i'm trying throttle how function executed via debounce requested function fires ajax call. debounce function below doesn't seem firing @ all.

i wrote own debounce service , have resorted using underscores debounce method test whether wrote incorrect or not turns out angular isn't liking below...

using angular's ng-model-option debounce method in html not option.

$scope.$watch('filters.monthlycost', function () {      _.debounce(function () {         console.log('lol');     }, 1000);  }); 

there no console errors, console.log('lol') never happens.

note: $watch does execute.

since debounce returns function ((function): returns new debounced function.) return value of debounce needs executed,

i.e example:

_.debounce(function () {         console.log('lol');     }, 1000)(); 

you do:

$scope.$watch('monthlycost', _.debounce(function() {         console.log('lol');     }, 1000)); 

Comments

Popular posts from this blog

Magento/PHP - Get phones on all members in a customer group -

php - .htaccess mod_rewrite for dynamic url which has domain names -

Website Login Issue developed in magento -