I have this function get_events();
There is a method that i call refresher.complete() when the data in the get_events is loaded?
this is my code
doRefresh(refresher) {
this.get_events();
setTimeout(() => {
console.log('Async operation has ended');
refresher.complete();
}, 1500);
}
in this case the refresher complete after 1500 ms
Thank You!
What does get_events() returns? A Promise, an Observable?
get_events() {
this.http.get("http://www.cinemairis.it/wp-json/wp/v2/events").subscribe(data => {
this.todayitems = JSON.parse(data['_body']).today;
this.afteritems = JSON.parse(data['_body']).after;
this.sponsoreditems = JSON.parse(data['_body']).sponsored;
this.total = this.todayitems.length;
this.loading.dismiss();
},
error => {
console.log(error);
setTimeout(() => {
let alert = this.alertCtrl.create({
title: "Nessuna Connessione",
subTitle: "Si prega di riprovare",
buttons: ["OK"]
});
alert.present();
}, 1000);
console.log(error);// Error getting the data
});
}
You can pass the ‘refresh’ object to the get_events() method and inside the subscribe call the refresh.complete()
But I think this is not a good pattern.
In my opinion, get_events() should return an Observable and the, who calls it deal with the subscribe() and what happens inside.
Thank you can You wrote a good pattern for this section?
I call get_events in the constructor for fill the fields in the html page