I had the same issue in my project. Version: "7.1.0".
So my solution for that is to create some boolean variable for loading more items.
When you are loading some data from the API set it to true - after that to false.
Example of using that in your function.
onReachEnd(): void {
if (this.isLoadingData) {
return;
}
// Call the API/function for more items here
}
Since I don't know if you have some service for handling requests etc. I will show you some example by using BehaviorSubject.
Let say that you service is named dataService
.
We can create here BehaviorSubject
- isLoadingData.
private isLoadingDataBehaviorSubject BehaviorSubject<boolean> = new BehaviorSubject(false);
and since it's service we can create here public
observable:
isLoadingData
= this.isLoadingDataBehaviorSubject.asObservable();`
Now when we got that all, we can create function to call API inside this service:
loadData(): Observable<any> {
this.isLoadingDataBehaviorSubject.next(true);
return this.http.get(url).pipe(
tap((response) => {
this.isLoadingDataBehaviorSubject.next(false);
return response;
}),
catchError((error: HttpErrorResponse) => {
this.isLoadingDataBehaviorSubject.next(false);
return of({});
})
);
}
And you have also to subscribe to this isLoadingData inside your component and set it's value.
Easiest way just for example:
ngOnInit(): {
this.dataService.isLoadingData.subscribe(x => {
this.isLoadingData = x;
});
}