1

I want to fix some new panel when window is scrolled but, whenever I scrolled window then $(window).scroll(fucntion(){ }); is not triggered. This function is in my angular controller.

This is at angular controller but when I scroll it isn't triggered

$(window).scroll(function () {
            console.log(" i Like it");
        //$scope.$apply();
    });

I also tried this.

$(document).ready(function(){ 
$(window).scroll(function () {
            console.log(" i Like it");
        //$scope.$apply();
    });
});

But it's also not working. Please help.

1

2 Answers 2

1

May I ask why are you using parenthesis? ($(window))

Please try following code:

app = angular.module('myApp', []);
app.controller("ctrl", function ($window) {
  var i = 0;

    $window.onscroll = function(){
     console.log(" i Like it: " + i++);
   };
});

Should be triggered by window scroll. But honestly you should really consider the use of directives instead.

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

1 Comment

please also add the $window as dependency of your controller.
0

when you work with angular you have to think about separation of concerns. You shouldn't add this kind of functionality inside of an angular controller. If you want to do something with the DOM probably you should use an angular directive.

Regards

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.