0

I am currently using an event listener to check whether a user scrolled up or down. The event listener does fire when the mouse is scrolled using but when I want to call on another function it says that it is not a function or on a variable it says that it is not there or undefined/NaN if its a type number. I thought that this might be a scoping issue or a binding issue but I can't dial down on how to solve it.

 ngOnInit() {
    var homeelement:HTMLElement=document.querySelector( '.homebackground' ) as HTMLElement;
    homeelement.addEventListener('wheel', this.findScrollDirectionOtherBrowsers);
  }

  findScrollDirectionOtherBrowsers(event){
    var delta;
    if (event.wheelDelta){
        delta = event.wheelDelta;
    }else{
        delta = -1 * event.deltaY;
    }

    if (delta < 0){
    //////////
    //if i call a function/variable here it says that its not there or undefined if its a variable
     this.callme()

    }else if (delta > 0){
        console.log("UP");
    }
  }
callme(){
console.log("gotcalled")
}
Luca Kiebel
  • 9,790
  • 7
  • 29
  • 44
ebbandflows
  • 63
  • 3
  • 8
  • 2
    You can define the callback as an arrow function: `findScrollDirectionOtherBrowsers = (event) => { ... }`. Or use this syntax: `addEventListener('wheel', this.findScrollDirectionOtherBrowsers.bind(this));`. – ConnorsFan Sep 14 '18 at 20:01
  • thank you connorsfan for your help, that callback solved the problem. After reading the other article you posted I can see why this binding works. I will make this post solved – ebbandflows Sep 14 '18 at 20:14

0 Answers0