ionic loading list code example
Example 1: ionic infinite scroll
<ion-content>
<ion-button (click)="toggleInfiniteScroll()" expand="block">
Toggle Infinite Scroll
</ion-button>
<ion-list></ion-list>
<ion-infinite-scroll threshold="100px" (ionInfinite)="loadData($event)">
<ion-infinite-scroll-content
loadingSpinner="bubbles"
loadingText="Loading more data...">
</ion-infinite-scroll-content>
</ion-infinite-scroll>
</ion-content>
import { Component, ViewChild } from '@angular/core';
import { IonInfiniteScroll } from '@ionic/angular';
@Component({
selector: 'infinite-scroll-example',
templateUrl: 'infinite-scroll-example.html',
styleUrls: ['./infinite-scroll-example.css']
})
export class InfiniteScrollExample {
@ViewChild(IonInfiniteScroll) infiniteScroll: IonInfiniteScroll;
constructor() {}
loadData(event) {
setTimeout(() => {
console.log('Done');
event.target.complete();
if (data.length == 1000) {
event.target.disabled = true;
}
}, 500);
}
toggleInfiniteScroll() {
this.infiniteScroll.disabled = !this.infiniteScroll.disabled;
}
}
Example 2: ionic loading
import { Component } from '@angular/core';
import { LoadingController } from '@ionic/angular';
@Component({
selector: 'loading-example',
templateUrl: 'loading-example.html',
styleUrls: ['./loading-example.css']
})
export class LoadingExample {
constructor(public loadingController: LoadingController) {}
async presentLoading() {
const loading = await this.loadingController.create({
message: 'Please wait...',
duration: 2000
});
await loading.present();
const { role, data } = await loading.onDidDismiss();
console.log('Loading dismissed!');
}
async presentLoadingWithOptions() {
const loading = await this.loadingController.create({
spinner: null,
duration: 5000,
message: 'Click the backdrop to dismiss early...',
translucent: true,
cssClass: 'custom-class custom-loading',
backdropDismiss: true
});
await loading.present();
const { role, data } = await loading.onDidDismiss();
console.log('Loading dismissed with role:', role);
}
}