I am implementing angularjs with an input field for numbers. I want to trigger an action automatically after a certain amount of time, but only if no further changes have been made to the number within that time frame (let's say 2 seconds).
In my example on Plunker, the action is currently being called every time the number changes. However, I would like the action to be executed only when the user has not made any changes to the value for more than 2 seconds.
<div class="col-md-3 divGridText">
<label for="excludeMinutesStep" style="font-weight:bold">Exclude tasks < </label>
<input id="excludeMinutesStep" min="0" max="10" ng-model="excludeValue" ng-change="numericStepperChanged(excludeValue)" size="2" style="width:40px;" type="number" /> <b>minutes</b>
</div>
$scope.excludeValue = 5;
$scope.numericStepperInitValue = 0;
$scope.numericStepperChanged = function(data) {console.log("A");
$scope.numericStepperHit = true;
if (data != undefined) {
$scope.excludeValue = data;
if (data == 0) {
$scope.isExcludeNeeded = false;
}
if ($scope.numericStepperInitValue == 0) {
$timeout($scope.callAtNumercStepperChangeTimeout, 2000);
}
}
}
$scope.callAtNumercStepperChangeTimeout = function() {
$scope.numericStepperHit = false;
$scope.numericStepperInitValue++;
$scope.changeGraph();
}
$scope.changeGraph = function() {
if (!$scope.numericStepperHit) {
console.log("Action called "+$scope.excludeValue);
$scope.mytext = "Action called "+$scope.excludeValue;
$scope.isExcludeNeeded = true;
}
}