Overview:
I make a network request to fill a list when my page loads in an Ionic 2 app. At this moment I am toggling a ion-spinner when the page initially loads.This is the refresher currently:
<ion-refresher (ionRefresh)="doRefresh($event)">
<ion-refresher-content
pullingText="Pull to refresh..."
refreshingSpinner="circles">
</ion-refresher-content>
</ion-refresher>
<ion-spinner *ngIf="loading" color="light" name="circles"></ion-spinner>
My desired behavior would be to remove the ion-spinner component and just enable the ion-refresher when the page initially loads. I've seen a couple examples of this with Ionic V1, but I cant seem to translate it over to Angular 2.
Question:
Is there a way to trigger the ion-refresher and its spinner from my controller (*.ts), so I can remove the extra ion-spinner component from my template?
In this HTML file, we need to add <ion-refresher> component where we call the Refresh event. Inside this component, add the <ion-refresher-content> sub-component which contains the custom refresher properties.
The refresher provides pull-to-refresh functionality on a content component. The pull-to-refresh pattern lets a user pull down on a list of data using touch in order to retrieve more data. Data should be modified during the refresher's output events.
ion-refresher The Refresher provides pull-to-refresh functionality on a content component. Place the ion-refresher as the first child of your ion-content element. Pages can then listen to the refresher's various output events.
I actually found a hack:
import { Content, Refresher } from 'ionic-angular';
export class MyPage {
@ViewChild(Content) content: Content;
@ViewChild(Refresher) refresher: Refresher;
...
ionViewDidEnter() {
this.refresher._top = this.content.contentTop + 'px';
this.refresher.state = 'ready';
this.refresher._onEnd();
}
This will show and trigger the refresher. It implicitly calls the registered refresh function.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With