I have the following which does a watch on an field that\'s bound to $scope.id. Every time the input field value changes the watch function gets e
I know the question asks for a lodash solution. Anyway here is an angular only solution:
app.factory('debounce', function($timeout) {
return function(callback, interval) {
var timeout = null;
return function() {
$timeout.cancel(timeout);
var args = arguments;
timeout = $timeout(function () {
callback.apply(this, args);
}, interval);
};
};
});
In the controller:
app.controller('BlaCtrl', function(debounce) {
$scope.$watch("id", debounce(function (id) {
....
}, 1000));
});