Integrate the pull to refresh feature in Ionic 3 with Wordpress


#1

I’m working on a Ionic3 app integrated with Wordpress using REST API v2 and I need to include the pull to refresh feature but I don’t understand how to do it with my code.

This is my function that retrieves my post

getPostsWordpress(){
    if(!(this.posts.length > 0)){
      let loading = this.loadingCtrl.create();
      loading.present();
      this.wordpressService.getRecentPostsWithSort(this.categoryId,this.sort) 
      .subscribe(data => {
        for(let post of data){
          post.excerpt.rendered = post.excerpt.rendered.split('<a')[0] + "</p>";
          this.posts.push(post);
        }
        loading.dismiss();
      });
    }
  }

doInfinite(infiniteScroll) {
    let page = (Math.ceil(this.posts.length/10)) + 1;
    console.log("PAGE_"+page)
    console.log("this.posts.length_"+this.posts.length)
    let loading = true;

    this.wordpressService.getRecentPostsWithSort(this.categoryId,this.sort, page)
    .subscribe(data => {
      for(let post of data){
        if(!loading){
          infiniteScroll.complete();
          
        }
        post.excerpt.rendered = post.excerpt.rendered.split('<a')[0] + "</p>";
        this.posts.push(post);
        loading = false;
      }
    }, err => {
      this.morePagesAvailable = false; 
    }) 
  }  

doInfinite let me to implement infinite scroll, and all works well!

How is it possibile to integrate pull to refresh from the ionic documentation?
This is a sample from the doc and I don’t understand how could I use it in my project.

doRefresh(refresher) {
    console.log('Begin async operation', refresher);

    setTimeout(() => {
      console.log('Async operation has ended');
      refresher.complete();
    }, 2000);
  }

Someone can help me?
Thank you in advance!