1

I am using this https://github.com/prajwalkman/angular-slider and I am trying to bind the slider events onStart and onMove that seem to be built in to the directive.

The HTML for the module is

<slider floor="0" ceiling="100" step="1" precision="1" ng-model="playhead" id="seekBar"></slider>

and I want to be able to use the events in my controller. I tried:

seekBar.addEventListener('onMove', function(event){...});

but didn't have any luck with that. Can anyone explain how I am supposed to use these events from my controller?

11
  • 1
    Where are you seeing that he provided a way to bind to those events? Commented May 9, 2014 at 18:27
  • why don't you use the ng-model value instead to binding to onMove event? Commented May 9, 2014 at 18:30
  • The version you linked there is clearly marked as deprecated. I would check this one out: https://github.com/venturocket/angular-slider. I don't see any documentation saying you can define custom event handlers for onMove or onStart on either page however. Commented May 9, 2014 at 18:38
  • Looks like you can see onMove in the (blech) CoffeeScript here: github.com/prajwalkman/angular-slider/… Commented May 9, 2014 at 18:39
  • 1
    @MarcKline, that did it. I just did a scope.$emit('onMove'); and then a $scope.$on('onMove', function(event){log($scope.playhead)}); and it shows me the value when I slide Commented May 9, 2014 at 19:41

1 Answer 1

1

Since you're willing to edit the directive's source, you can inject your own Angular $emit inside of its own internal onMove handler:

// emit 'onMove' up the scope chain
scope.$emit('move');

Then, assuming your controller's scope is the parent of the directive, you can just insert the following into the controller:

$scope.$on('move', function(){
  console.log("move fired");
});

Plunker demo

You might consider debouncing the event handling a bit to avoid excessive responses to the event - whether or not that's useful for you depends on what you're doing.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.