I have a system in place that retrieves documents and displays their metadata on a web page without any issues. However, I am looking to incorporate an "infinite scrolling" feature. After some research, I came across npm i angular2-infinite-scroll
Currently, I am using an observable for the documents and leveraging the async pipe within an *ngFor
loop
document-list.ts
export class DocumentList implements OnInit {
documents: Observable<Array<Document>>;
chunck: number = 100;
from: number = 0;
keyword: string = "";
constructor(private _documentService: DocumentService) {}
ngOnInit() {
this.documents = this._documentService.getDocuments(this.chunck, this.from, this.keyword);
}
}
Using angular2-infinite-scroll, I have implemented a function that triggers when I reach the bottom of the page. My goal is to load more documents and display their metadata alongside the existing ones
onScroll() {
this.from = documents.length ... ?
//this.documents = this._documentService.getDocuments(this.chunck, this.from, this.keyword);
}
I'm uncertain if this approach is feasible with an observable. If I switch to using a simple array for documents like documents: Document[]
, I could potentially do something similar to
onScroll() {
this._documentService.getDocuments(this.chunck, this.from, this.keyword)
.subscribe(documents => this.documents.push(documents));
}
Open to other suggestions or ideas?