Within my controller, I have the following code:
$scope.woffset = window.pageYOffset;
$scope.$watch("woffset", function (newValue, oldValue) {
console.log("hello");
console.log(window.pageYOffset);
}, true);
});
My expectation is to receive console logs of "hello" as the pageYOffset changes while scrolling. Unfortunately, it doesn't seem to be working as intended. However, when manually checking window.pageYOffset in the console as I scroll down, I can see that the value is indeed changing. Any suggestions on what might be causing this issue?
I've attempted various iterations with watch methods, including using functions instead of strings and experimenting with different parameters like "true", but so far, nothing has resolved the problem.
(I am aware there is an alternative solution involving onscroll, but I'm interested in understanding why this particular approach is not functioning correctly) Thank you for your assistance!
Edit: Even trying the following modification didn't yield the desired outcome:
$scope.test = function () {
return window.pageYOffset;
}
$scope.$watch("test", function (newValue, oldValue) {
console.log("hello");
console.log(window.pageYOffset);
}, true);