Angular Core Dependency: >=1.2.0
Module License: MIT
Added by: Sam Deering
AngularJS debounce service and directive
Service - Creates and returns a new debounced version of the passed function which will postpone its execution until after wait milliseconds have elapsed since the last time it was invoked. Useful for implementing behavior that should only happen after the input has stopped arriving. For example: recalculating a layout after the window has stopped being resized.
Directive - Can be added to any element with an ng-model attribute and postpone model updates by user input until after wait milliseconds have elapsed since the last user input. Useful for watchers that should only be invoked after the input has stopped arriving. For example: rendering a preview of a Markdown comment.
Install using bower
bower install --save ng-debounce
Include script tag in your html document.
Add a dependency to your application module.
debounce(func, wait, [immediate])
|func|function|The function we want to debounce|
|wait|number|Number of miliseconds to wait before invoking the debounced function|
true for the immediate parameter to cause debounce to trigger the function on the leading instead of the trailing edge of the wait interval. Useful in circumstances like preventing accidental double-clicks on a "submit" button from firing a second time.|
A debounced version of the passed function. Any arguments passed to this function will be also passed to the passed function in case this invocation will trigger the function.
The returned function also has a
cancel() method which can be used in case you what to reset the current debounce state. This will prevent the function from being triggered even after wait miliseconds have passed from last input. In case immediate is
true, this means that the next user input will trigger the debounce.
<input type="text" ng-model="blah" debounce="500"></input> <input type="checkbox" ng-model="blah" debounce="500" immediate="true"></input> etc.
|debounce|number|Number of miliseconds to wait before triggering the model update|
true for the immediate parameter to cause debounce to trigger model update on the leading instead of the trailing edge of the wait interval.|
The debounce service is based on the debounce implementation in uderscorejs
The MIT License.
Module stats last updated: 2017-03-09 15:00:04