Last active
September 8, 2024 22:39
-
-
Save rarous/5625751 to your computer and use it in GitHub Desktop.
rx-throttle directive for angular.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| directive('ngThrottle', function () { | |
| return { | |
| restrict: 'A', | |
| require: 'ngModel', | |
| link: function (scope, elm, attr, ngModelCtrl) { | |
| if (attr.type === 'radio' || attr.type === 'checkbox') return; | |
| elm.unbind('input').unbind('keydown').unbind('change'); | |
| var disp = elm.keyupAsObservable(). | |
| throttle(attr.ngThrottle). | |
| select(function(){ return elm.val() }). | |
| subscribe(function (x) { | |
| scope.$apply(function () { ngModelCtrl.$setViewValue(x) }) | |
| }); | |
| elm.bind('$destroy', disp.dispose); | |
| } | |
| } | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment