I have a event handler in my AngularJS directive:
angular.element($window).on("wheel", onScrollAction);
Before onScrollAction
in my directive I have defined some variables, outside of the onScrollAction
function itself because I don't want them assigned on every wheel event, as they shouldn't change.
app.directive('scroll', function ($window) {
return function(scope, element, attrs) {
var elem = angular.element(document.querySelectorAll('.titletitle')).eq(1);
var elemHeight = elem[0].scrollHeight;
//so on until the 5th element
//then object to store all the elements and their heights:
var theObject = [{el:elem,elH:elemHeight},{el:elem2,elH:elem2Height},{el:elem3,elH:elem3Height},{el:elem4,elH:elem4Height},{el:elem5,elH:elem5Height}]
var theActiveElem = theObject[0];
var onScrollAction = function (event) {
console.log(theActiveElem) //renders undefined
console.log(elem) // renders the element
My question is, how come the elem
is fine going from a global scope to a function scope, when theActiveElem
is not and how do I fix it so I can do actions on theActiveElem
in my event handler.
Thank you.