Pull to refresh trigger on ionViewDidEnter - Need to pass event object

Hi All, I am wondering how I can trigger the pull to refresh function using ionViewDidEnter().

I can easily just call my doRefresh() function in the ionViewDidEnter() method, but how can I pass in a $event object so that refresher.complete(); can still be called at the end of it.

ts

ionViewDidEnter() {

	this.doRefresh(); -- I need to pass in here somehow

}

doRefresh(refresher) {

	this.notificationservice.refreshNotifications().then((response) => {

		response = JSON.parse(response['_body']);

		let notifications = new Array();

		for(let key in response)
		{
			response[key].dateago = moment(response[key].date, 'YYYY-MM-DD H:mm:ss').fromNow();
			notifications[key] = response[key];
		}

		this.notifications = notifications;

		this.notificationservice.notifications = notifications;

		refresher.complete();
	});

}

html

<ion-refresher (ionRefresh)="doRefresh($event);">
		<ion-refresher-content pullingIcon="arrow-dropdown" pullingText="Pull to refresh" refreshingSpinner="circles" refreshingText="Refreshing...">
		</ion-refresher-content>
	</ion-refresher>

The way I have done this is to simply have 2 different refreshers/loaders. I’m not sure what you’re wanting to do is possible. In your case you could simply if(refresher) refresher.complete() to avoid an error, and just stick to using 1 function (though missing an animation so the user can see that it is refreshing, when they haven’t performed a pull to refresh)

Makes sense, I think I can deal with the lack of animation. Many Thanks for your time.

Try something like this,

    ionViewDidEnter() {
           this.doRefresh(null);

      }
     doRefresh(refresher)
     {
               ...
               if(refresher){
                 refresher.complete();
               }
      }

The null isn’t needed, if you want your compiler to stop complaining you should do

doRefresh(refresher?) { ... }
1 Like