我生成了json文件并将其添加到我的提供者之一“people.ts”:
getPeople(): Observable<any> {
return this.http.get("https://randomuser.me/api/?results=10")
}
然后我编写了2个函数,它们应该重新加载并在下面调用它们时添加更多的json对象(离子无限滚动和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>
答案 0 :(得分:1)
替换您的doRefresh
和doInfinite
,如下所示
doRefresh(e) {
this.service.getPeople().subscribe( (data) => {
this.people.unshift(...data.results);
}, (Error) => console.log(Error), () => e.complete());
}
doInfinite(e) {
this.service.getPeople().subscribe( (data) => {
this.people.push(...data.results);
},(Error) => console.log(Error),() => e.complete());
}