Infinite Scroll using Angular

Hi all, got a quick question regarding infinite scroll in angular.
I’ve implemented it, however it keeps duplicating the same api call multiples times. When removing the for-loop it doesn’t seem to work. Is there a workaround this?

Here’s the code below:
infinite-scroll.service.ts

 companyConversations: DtoCompanyResponse[]; getItemsCompany(page = 1, itemsPerPage = 10): Observable<DtoCompanyResponse[]> { const startIndex = (page - 1) * itemsPerPage; const endIndex = startIndex + itemsPerPage; this.companyConversations = []; for (let i = startIndex; i < endIndex; i++) { const bankerRequestObject = { bankerUsername: sessionStorage.getItem("msal.usrname"), isChat: true, teamId: Number(this.teamId), pageNumber: page, searchParam: "" }; this.conversationService.getCompanyConversations(bankerRequestObject) .subscribe((response: DtoBankerConversationCompanyResponse[]) => { this.companyConversations = response; }); } return of(this.companyConversations).pipe(); } 
Enter fullscreen mode
Exit fullscreen mode

Discover more from Coursity

Subscribe to get the latest posts sent to your email.

Leave a Comment

Your email address will not be published. Required fields are marked *

Discover more from Coursity

Subscribe now to keep reading and get access to the full archive.

Continue reading

Scroll to Top
Additionally, our **high performance linux vps for web hosting** offers a scalable solution that can grow with your business. Install docker compose ubuntu.