npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

ng-debounce-throttle

v1.0.1

Published

AngularJS services for debounce and throttle.

Downloads

231

Readme

ng-debounce-throttle

AngularJS services for debounce and throttle.

Why another AngularJS debounce/throttle module?

I know that there already are various versions of modules that provide services for debounce and throttle. However, most of them had something missing. I wanted:

  • debounce and throttle service combined in one module
  • leading, trailing flags
  • invokeApply flags
  • cancel() method

Code and documentation is partly adopted from

Other/similar modules are: ng-debottle, angular-debounce-throttle, angular-throttle-debounce, angular-debounce

Installation

Install via Bower:

bower install --save ng-debounce-throttle
<script src="bower_components/ng-debounce-throttle/ng-debounce-throttle.js"></script>

Install via NPM:

npm install --save ng-debounce-throttle
<script src="node_modules/ng-debounce-throttle/ng-debounce-throttle.js"></script>

Add dependency to your app module:

angular.module('myApp', ['ngDebounceThrottle']);

Usage

$debounce

Service that creates and returns a new debounced version of the passed function, which will postpone its execution until after delay 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.

$debounce(func, delay, [leading=false], [invokeApply=true]);

Arguments

|Param|Type|Details| |---|---|---| |func|function|The function we want to debounce.| |delay|number|Number of milliseconds to wait before invoking the debounced function.| |leading (optional)|boolean|If true, the function is triggered on the leading instead of the trailing edge of the delay interval. Useful for circumstances like preventing accidental double-clicks on a "submit" button from firing a second time. Default: false| |invokeApply (optional)|boolean|If true, an angular digest cycle is triggered (see $timeout service for more details). Default: true|

Returns

A debounced version of the passed function. Any arguments passed to this function will be also passed.

The returned function also has a cancel() method, which can be used in case you want to reset the current debounce state. This will prevent the function from being triggered even after delay milliseconds have passed from last input. In case leading is true, the next user input will trigger the debounce.

Example

angular.module('myApp').controller('myCtrl', ['$element', '$debounce', function ($element, $debounce) {

    var onMouseMove = $debounce(function () {
        console.log('Mouse is resting inside element');
    }, 1000, false, false);

    $element.on('mousemove', onMouseMove);

    $element.on('mouseleave', function () {
        onMouseMove.cancel();
    });

}]);

$throttle

Service that creates and returns a new throttled version of the passed function, which will trigger its execution only every delay milliseconds. This is useful to tear down fast iterative events, like window.resize.

$throttle(func, delay, [leading=false], [trailing=true], [invokeApply=false]);

Arguments

|Param|Type|Details| |---|---|---| |func|function|The function we want to throttle.| |delay|number|Number of milliseconds to wait between each input before invoking the function.| |leading (optional)|boolean|If true, the function will be invoked at the startup. Default: false| |trailing (optional)|boolean|If true, the function will be invoked at end of the operation. Default: true| |invokeApply (optional)|boolean|If true, an an angular digest cycle is triggered each time the function is invoked. Default: false|

Returns

A throttled version of the passed function. Any arguments passed to this function will be also passed.

The returned function also has a cancel() method, which can be used in case you want to reset the current throttle state. This will cause that the next input will trigger the function immediately.

Example

angular.module('myApp').controller('myCtrl', ['$element', '$throttle', function ($element, $throttle) {

    var onMouseMove = $throttle(function (event) {
        console.log(event.offsetX, event.offsetY);
    }, 500);

    $element.on('mousemove', onMouseMove);

}]);

License

See License