By using the this keyword inside the Unshown functions, you are setting properties of that function object. To access those properties outside the function, use the property accessor on the function object reference.
twittyApp.factory('Unshown', function () {
function Unshown() {
this.allIsLoaded = false;
this.loading = false;
this.firstTime = true;
this.scrollMarker = 100;
this.loadedUnshownPages = 0;
this.timeLineHiader = $cookies.get("lastReadedTweetId");
}
window.onscroll = function () {
//this.scrollMarker is undefined
//
//Use property accessor
console.log(Unshown.scrollMarker);
};
return Unshown;
});
Using window.onscroll in AngularJS
Using window.onscroll is the Older way to register event listeners.
In AngularJS, event listeners are added using Angular's jqLite.
var windowElem = angular.element($window);
windowElem.on('scroll', function scrollListener (event) {
console.log(event);
};
Be sure to add $window to the list of injectables for the factory function.