In my controller, I have:
$scope.woffset = window.pageYOffset;
$scope.$watch("woffset", function (newValue, oldValue) {
console.log("hello");
console.log(window.pageYOffset);
}, true);
});
So, when I scroll, I should get the hello console logs when changing pageYOffset. However, he does nothing. But if I run window.pageYOffset in the console while scrolling down, I see that the value is changing. Any ideas?
I tried several variations of the clock (with and without true, using functions instead of strings, but nothing works).
(I know there is work with onscroll, but I would like to know how it will work like that) Thanks!
Edit: this doesn't work either:
$scope.test = function () {
return window.pageYOffset;
}
$scope.$watch("test", function (newValue, oldValue) {
console.log("hello");
console.log(window.pageYOffset);
}, true);
source
share