javascript - Input trigger with delay function, wait if input value changes -
i'm building angular directive, on input value change runs function, want wait 300ms before running function, if value changes before 300ms has gone, need reset delay 300ms. if value changes 300ms function should run:
my code
(function() { 'use strict'; angular .module('address',[]) .directive('address', ['address', function (address) { return { restrict: 'e', transclude: true, templateurl: 'partials/address.html', link: function (scope, elem, attrs) { var delay = "300"; scope.$watch('searchparam', function(){ if(!_.isundefined(scope.searchparam) && scope.searchparam.length >= 3) { // here need delay timer address.get(scope.searchparam).then(function(data){ console.log("data: ", data); scope.addresslist = data; }, function(status){ console.log("status: ", status); scope.errorhandler = status; }); } }); } }; }]); })();
the address.get async service returns addresses
what want debouncing. it's included in js libraries.. , standard of angularjs 1.3
Comments
Post a Comment