문서를 가져 와서 잘 작동하는 페이지에 메타 데이터를 나열하는 서비스가 있습니다. 나는 "무한 스크롤"을 구현하려는 내가항목을 관측 가능한 배열에 Angular2로 추가 하시겠습니까?
문서 list.ts
문서에 대한 관찰과*ngFor
루프에서 비동기 파이프를 사용하고 순간
npm i angular2-infinite-scroll
보았다
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);
}
}
angular2-infinite-scroll에서는 페이지 맨 아래로 스크롤 할 때 호출되는 함수가 있는데, 더 많은 문서를 가져와 이미있는 페이지로 메타 데이터를 표시하는 것입니다.
onScroll() {
this.from = documents.length ... ?
//this.documents = this._documentService.getDocuments(this.chunck, this.from, this.keyword);
}
관찰 가능을 사용할 때 이것이 가능한지 확실하지 않습니까? 나는이 문서에 대한 간단한 배열을 사용하는 경우 대신 documents: Document[]
나는
onScroll() {
this._documentService.getDocuments(this.chunck, this.from, this.keyword)
.subscribe(documents => this.documents.push(documents));
}
다른 아이디어 같은 것을 할 수 있습니까?
감사 : 주제에 대한 추가 정보를 원하시면
–