Can I pass parameters to a function debounced with _.lodash?
UPDATE
You should pass an argument into the function: _.debounce(function (pid) {
$scope.parsePid = _.debounce(function(pid){ $scope.$apply(function(){ if (pid === null || pid === "") { $scope.pidLower = null; $scope.pidUpper = null; } else if (pid.indexOf("-") > 0) { pid = pid.split("-"); $scope.pidLower = parseInt(pid[0],10); $scope.pidUpper = parseInt(pid[1],10); } else { $scope.pidLower = parseInt(pid,10); $scope.pidUpper = null; } });},1500);
I would use the built-in $timeout
var promise;$scope.parsePid = function(pid){ $timeout.cancel(promise); promise = $timeout(function(){ if (pid === null || pid === "") { $scope.pidLower = null; $scope.pidUpper = null; } else if (pid.indexOf("-") > 0) { pid = pid.split("-"); $scope.pidLower = parseInt(pid[0],10); $scope.pidUpper = parseInt(pid[1],10); } else { $scope.pidLower = parseInt(pid,10); $scope.pidUpper = null; } },1500);};