I have a problem using Angular2. If I'm not mistaken in Angular2 I should put my code in class instead of controller and access variables by this
but I have a variable I want to access from function assigned to window.onscroll
, and this
inside this function doesn't work, because it return window
.
How can I access my variables or functions on scroll event?
class someClass{
someVariable;
ngOnInit() {
this.someVariable = {};
window.onscroll = function() {
// here I want to access someVariable or someFunction
}
}
someFunction() {
}
}