Joined November 2013
·

Erlend Strømsvik

Ny Media AS
·
·

Posted to [AngularJS] HTML5 Autocomplete over 1 year ago

Could not get your directive to work. This is what I ended up with:

.directive('keyboardPoster', ['$timeout', function($timeout) {
  var DELAY_TIME_BEFORE_POSTING = 200;
  return function(scope, elem, attrs) {

    var element = angular.element(elem)[0];
    var currentTimeout = null;

    element.oninput = function() {
      var poster = scope[attrs.postFunction];

      if(currentTimeout) {
        $timeout.cancel(currentTimeout)
      }

      currentTimeout = $timeout(function() {
        poster(angular.element(element).val());
      }, DELAY_TIME_BEFORE_POSTING);
    }
  }
}]);
Achievements
1 Karma
0 Total ProTip Views