Reputation: 10386
I am using the below infinite scroll directive:
https://github.com/orizens/angular2-infinite-scroll
But the thing is when I use this directive on one page, and if I move away from that page the scrolled event is still fired, probably because of below line in the scroller.ts file:
return this.container.addEventListener('scroll', this.handler.bind(this));
This event listener is added but not removed when we move away from the page.
Any clue, how to handle it automatically, when we switch to another page?
Upvotes: 1
Views: 2094
Reputation: 658235
Either you add the event handler declaratively
<div class="container" (scroll)="handler($event)"></div>
or you use
ngOnDestroy() {
this.container.removeEventListener('scroll', this.handler);
}
Upvotes: 1