我生成了一个JSON文件,并将其添加到我的一个提供程序“people.ts”中:
getPeople(): Observable<any> {
return this.http.get("https://randomuser.me/api/?results=10")
}
然后我写了2个函数,它们应该在调用后重新加载并添加更多JSON对象(ionic infinite scroll和doRefresh函数)如下:
constructor(public navCtrl: NavController,
public service: People)
{
this.service.getPeople().subscribe( data => {
this.people = data.results
});
}
doRefresh(e) {
this.service.getPeople()
this.service.getPeople().subscribe( data => {
this.people.unshift(...data.results),
Error => console.log(Error),
() => e.complete()
});
}
doInfinite(e) {
this.service.getPeople()
this.service.getPeople().subscribe( data => {
this.people.push(...data.results),
Error => console.log(Error),
() => e.complete()
});
}
问题是两者都只工作一次(它们刷新和添加),循环从未停止旋转。我该怎么办?
Photo of spinning circle in app
我就是这么称呼他们的:
<ion-refresher (ionRefresh)="doRefresh($event)">
<ion-refresher-content>
</ion-refresher-content>
</ion-refresher>
<ion-infinite-scroll (ionInfinite)="doInfinite($event)">
<ion-infinite-scroll-content>
</ion-infinite-scroll-content>
</ion-infinite-scroll>
1条答案
按热度按时间q43xntqr1#
如下所示替换您的
doRefresh
和doInfinite