'window.removeEventListener not working in Angular

I can't for the life of me find out, why the eventlistener isn't removed on the mouseup event. I have already tried a lot of different things, but I can't remove it.

The function that creates the eventListeners:

dragKnob(event: MouseEvent) {
    window.addEventListener('mousemove', this.drag);
    window.addEventListener('mouseup', this.stopDrag);
}

drag:

drag(event: MouseEvent) {
    const bar = document.getElementById('chosenBar');
    console.log('Percent: ' + (event.clientX - bar!.getBoundingClientRect().left) / bar!.offsetWidth);
}

stopDrag (where I'm trying to remove the eventListeners but without luck):

stopDrag() {
    console.log('Stopped drag');
    window.removeEventListener('mousemove', this.drag);
    window.removeEventListener('mouseup', this.stopDrag);
}

The console.log in stopDrag is executed, but the eventlisteners isn't removed.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source