Ionic4.x ion-infinite-scroll 上拉分页加载更多
2024-08-26 17:59:04
<ion-header>
<ion-toolbar>
<ion-title>
Tab One
</ion-title>
</ion-toolbar>
</ion-header> <ion-content> <ion-list>
<ion-item *ngFor="let item of list">
<ion-label>{{item.title}}</ion-label>
</ion-item>
</ion-list> <ion-infinite-scroll threshold="10%" (ionInfinite)="loadMore($event)">
<ion-infinite-scroll-content loadingSpinner="crescent" loadingText="加载中...">
</ion-infinite-scroll-content>
</ion-infinite-scroll> <p *ngIf="!hasMore">---我是有底线的---</p> </ion-content>
import { Component } from '@angular/core'; import { HttpserviceService } from '../services/httpservice.service'; @Component({
selector: 'app-tab1',
templateUrl: 'tab1.page.html',
styleUrls: ['tab1.page.scss']
})
export class Tab1Page { public list:any[]=[]; public page:any=1; public hasMore=true; constructor(public httpService:HttpserviceService){ }
ngOnInit(): void { this.getData();
} getData(){ var api='http://www.phonegap100.com/appapi.php?a=getPortalList&catid=20&page='+this.page;
this.httpService.get(api).then((response:any)=>{
console.log(response)
this.list=response.result;
++this.page;
}) }
loadMore(e){
var api='http://www.phonegap100.com/appapi.php?a=getPortalList&catid=20&page='+this.page;
this.httpService.get(api).then((response:any)=>{
console.log(response)
this.list=this.list.concat(response.result);
++this.page;
//判断下一页有没有数据
if(response.result.length<20){
e.target.disabled=true; this.hasMore=false;
}
e.target.complete(); //请求完成数据以后告诉ion-infinite-scroll更新数据
})
}
}
http服务:
import { Injectable } from '@angular/core';
import { HttpClient } from '@angular/common/http';
@Injectable({
providedIn: 'root'
})
export class HttpserviceService { constructor(public http:HttpClient) { } get(api){ return new Promise((resolve,reject)=>{
this.http.get(api).subscribe((response)=>{ resolve(response); },(err)=>{
reject(err); })
}) }
}
最新文章
- Java中private、protected、public和default的区别
- linux下QT程序输出乱码解决方法
- terminal崩溃打不开的一种原因以及ubuntu下matlab权限不够的解决办法
- PHP获取IP地址
- 89C51单片机实现的流水灯
- 微信JSSDK与录音相关的坑
- PHP接口的声明与引用
- 【转】Android 带checkbox的listView 实现多选,全选,反选 -- 不错
- 关于CSS选择器的效率问题
- 在MVC里使用 HttpContext.Response输出内容
- Java NIO系列教程(六) 多路复用器Selector
- vue.js下载及安装配置
- linux命令详解之df命令
- 【RL-TCPnet网络教程】第30章 RL-TCPnet之SNTP网络时间获取
- 【CSS】按钮的禁用与可用 CSS Cursor 属性
- 使用CompletionService结合ExecutorService批处理调用存储过程任务实例
- Redis集群方案怎么做?
- lldb调试mysql 插件命令
- BDD实战篇 - .NET Core里跑Specflow - 可以跑集成测试和单元测试
- 845. Greatest Common Divisor
热门文章
- WEB前端-搜索引擎工作原理与SEO优化
- yarn cluster和yarn client模式区别——yarn-cluster适用于生产环境,结果存HDFS;而yarn-client适用于交互和调试,也就是希望快速地看到application的输出
- LG4195 【模板】exBSGS
- (java)selenium webdriver学习---三种等待时间方法:显式等待,隐式等待,强制等待
- ORM框架三种映射在Springboot上的使用
- windows部署tomcat
- vue中input输入第一个字符时,光标会消失,需要再次点击才能输入
- Bash基本功能:输入输出重定向
- loj #2053 莫队
- 【概率论】6-4:分布连续性修正(The Correction for Continuity)