I'm trying to setup a pagination system in ıonic for Infinite Scroll. What I am trying to achieve is get data in block with a spesific amount (for example 10 data). Then, when the user reaches to the bottom, it should get another block of data starting from the last data it recorded. However, when I run my code, the query gives a result of a block with 1 data instead of 10.
I tried adding console logs and I tried to understand the problem. I shared the information I have.
feed.page.ts
export class FeedPage implements OnInit {
ideas: any;
offset =5;
nextKey: any;
prevKeys: any[] = [];
subscription: any;
data: any[] = [];
constructor(private afstore:AngularFirestore,
private feedsrvc:FeedService) { }
ngOnInit() {
this.getIdeas("5dd46790-b369-11e9-bd2b-a7c5019a82a5")
console.log("baş")
console.log(this.data)
}
loadData(event) {
setTimeout(() => {
console.log('Done');
console.log('Bak bu: '+this.nextKey);
this.getIdeas(this.nextKey);
event.target.complete();
}, 500);
}
private getIdeas(key?){
this.subscription = this.feedsrvc.getIdeas(this.offset,key).valueChanges().subscribe(ideas =>{
console.log("Adet: "+this.offset)
console.log("Önce")
console.log(ideas)
//this.ideas = ideas.slice(0,this.offset)
this.ideas = ideas
this.data=this.data.concat(this.ideas)
//console.log("ud"+this.ideas)
this.nextKey = `${ideas[this.offset].uuid}`})
console.log("Son Key: "+this.nextKey)
}
}
feed.service.ts
export class FeedService {
constructor(private afstore:AngularFirestore){}
getIdeas(offset, startKey?){
return this.afstore.collection('posts', ref => ref.limit(offset+1).orderBy("uuid").startAt(startKey))
}
}