I have a mock array inside of my caseService
, from this array data is distributed through the whole web-app.
To get the data inside of another component I use the following code:
this.cases = this.caseService.data;
It works fine, but there's one thing bothering me.
In one of my components I have an infinite scroll:
@HostListener('window:scroll', ['$event'])
scroll() {
const pos = (document.documentElement.scrollTop || document.body.scrollTop) + document.documentElement.offsetHeight;
const max = document.documentElement.scrollHeight;
if (pos === max) {
this.cases.push(...this.casesService.data);
// causes trouble
}
}
As the user scrolls, the array this.cases
is being pushed. It works fine, but when I leave this component by going back or routing somewhere else, this.cases
& even this.casesService.data
keep the amount of entries (amount depends on for how long the user scrolled) - hence every other component displays an increased amount of cases.
Reloading the page solves the issue again.