How do I make the returned server data persist or cache when pushing to another view? I use the current infinite scroll information found on the ionic 2 documentation, but I cannot make the initial server request stay within the view or the fetched data from the infinite scrolling. It keeps on reloading the http.get(url). I have done it with other server requests, but can’t seem to get it working with infinite scroll. What should be in the app.ts ?
import.....
@Page({....})
constructor(){
}
loadstartData(){
return new Promise(resolve => {
this.http.get('someURL.com/json&count=10')
.map(res => res.json())
.subscribe(data => {
resolve(data);
});
});
}
loadData(offset:number) {
return new Promise(resolve => {
this.http.get('someURL.com/json&offset='+offset+'&count=5')
.map(res => res.json())
.subscribe(data => {
resolve(data);
});
});
}
//Page.ts
import(Page, InifiniteScroll) from ...
import(DataServicel) from ...
@Page({...})
export class ListPage {
public listItems= [];
public offset = 10;
constructor(private dataService: DataService) {
}
ngAfterViewInit() {
this.getstartData();
}
getstartData(){
this.dataService.loadstartData().then(data => {
for (var i = 0; i < 10; i++) {
this.listItems.push( this.listItems.length );
}
});
}
doInfinite(infiniteScroll) {
setTimeout(() => {
this.dataService.loadData(this.offset).then(data => {
for (var i = 0; i < 5; i++) {
this.listItems.push( this.listItems.length );
}
});
infiniteScroll.complete();
this.offset = this.offset + 5;
}, 500);
}