Vimal
Vimal

Reputation: 2857

Is it possible to fire an event in div scroll in Angularjs?

How to trigger a div scroll event (not $document and $window) in Angularjs?

angular.element('div.myClassname').bind("scroll", function() {

});

Upvotes: 0

Views: 3316

Answers (2)

Pankaj Parkar
Pankaj Parkar

Reputation: 136134

Yes you could do, but it should be implemented through the directive. Directive will give you the control over that DOM element, should restrict" 'C' which will work for class

Markup

<div class="myClassname">
   ..Content here to scroll..
</div>

Directive

app.directive('myClassname', function(){
  return {
    restrict: 'C',
    link: function(scope,element, attrs){
       element.bind('scroll', function(){
         //do code here
       })
    }
  }
})

Upvotes: 2

initialxy
initialxy

Reputation: 1183

You know what you wrote there will work as long as div.myClassname has overflow: scroll; and its contents are bigger then its size. Though you have to use document.querySelector to query. See fiddle Though I must agree with Pankaj Parkar there that creating a directive is much more preferable.

Upvotes: 2

Related Questions