Skip to content

Latest commit

 

History

History
48 lines (31 loc) · 1.04 KB

File metadata and controls

48 lines (31 loc) · 1.04 KB

angular.throttle

This extension enables throttling for AngularJS. This is useful to tear down fast iterative events, like window.resize.

Installation

bower install angular-throttle
<script type="bower_components/angular-throttle/src/angular.throttle.js"></script>

Usage

// Declares a throttled function
// This function will be invoked by a minimum of 250 ms
var throttledResize = angular.throttle(function () {

    console.log('No browser drain at each event please.');

}, 250);

angular.element(window).on('resize', throttledResize);

Options

You can use some options:

angular.throttle(fn, delay, {
	leading: false,
	trailing: false
})

options.leading If leading is true the function will be invoked at the startup. Otherwise not. Default true.

options.trailing When trailing is set to false the function will not be invoked the end of the operation. Default true

The extension was inspired by UnderscoreJS so you are able to use the same options.

License

Do what you want.