私はドキュメントを取り出し、そのメタデータをうまく動作するページに一覧表示するサービスを持っています。私は「無限スクロール」を実装したいと私はアイテムを観測可能な配列に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);
}
}
angle2-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));
}
他のアイデアのようなものを行うことができますか?
ありがとう:被験者詳細は
–