angular.js+ionic上拉加载下拉刷新

页面效果
在这里插入图片描述
1.下拉刷新
使用ion-refresher,pulling-text下拉时的文本,refreshing-text刷新时的提示文本,on-refresh刷新方法。

<ion-refresher pulling-text="下拉刷新" refreshing-text="刷新中..." on-refresh="doRefresh()"></ion-refresher>

2.上拉加载
使用ion-infinite-scroll,can_loadmore判断是否有数据(没数据了,隐藏组件),loadMore()加载数据方法,distance开始加载时离底部的距离。

 <ion-infinite-scroll
         ng-if="can_loadmore"
         on-infinite="loadMore()"
         distance='1%'>  
 </ion-infinite-scroll>

3.页面代码

<ion-view view-title="" hide-nav-bar="true" hide-tabs ng-controller="insuranceConceptController">
    <ion-header-bar class="bar el-common-title product-center-title" align-title="center" header-height>
        <a class="button button-clear el-common-icon icon ion-ios-arrow-back" onclick="history.back()"></a>
        <h1 class="title el-common-text">保险理念</h1>
    </ion-header-bar>
    <ion-content class="content has-header ionic-pseudo">
            <ion-refresher pulling-text="下拉刷新" refreshing-text="刷新中..." on-refresh="doRefresh()"></ion-refresher>
            <div class="list card" ng-repeat="msg in listXXXX" ng-click="toInsuranceConceptDetail(msg.age)">
                <div class="item">
					<span style="font-size: 16px">
					{{msg.title}}
					</span>
                </div>
                <div class="item item-image">
                    <img src="{{msg.img}}" style="height: 150px">
                </div>
                <span class="item" style="font-size: 14px;color: #d0d0d0">
					<span>{{msg.time}}</span>
					<span style="float: right;">查看详情
						<i style="margin-left: 6px;" class="icon ion-chevron-right"></i>
					</span>
				</span>
            </div>
        <ion-infinite-scroll
                ng-if="can_loadmore"
                on-infinite="loadMore()"
                distance='1%'>
        </ion-infinite-scroll>

    </ion-content>
</ion-view>

4.部分js代码

  $scope.listXXXX = [
            {"title": "简单了解保险理念", img: "https://p2.piqsels.com/preview/680/431/623/boy-child-kid-family.jpg",time:"2019-10-12"},
            {"title": "简单了解保险理念", img: "https://p2.piqsels.com/preview/680/431/623/boy-child-kid-family.jpg",time:"2019-10-12"},
            {"title": "简单了解保险理念", img: "https://p2.piqsels.com/preview/680/431/623/boy-child-kid-family.jpg",time:"2019-10-12"},
            {"title": "简单了解保险理念", img: "https://p2.piqsels.com/preview/680/431/623/boy-child-kid-family.jpg",time:"2019-10-12"},
            {"title": "简单了解保险理念", img: "https://p2.piqsels.com/preview/680/431/623/boy-child-kid-family.jpg",time:"2019-10-12"}
            ];
        var page_no = 1;
        $scope.can_loadmore = true;


        $scope.doRefresh = function () {
            page_no = 1;
            $scope.$broadcast('scroll.refreshComplete');
        };

        $scope.loadMore = function () {
            page_no++;
            if (page_no === 10) {
                $scope.can_loadmore = false;
                $scope.$broadcast('scroll.infiniteScrollComplete');
            } else {
                var newData = [
                    {"title": "简单了解保险理念", img: "https://p2.piqsels.com/preview/680/431/623/boy-child-kid-family.jpg",time:"2019-10-12"},
                    {"title": "简单了解保险理念", img: "https://p2.piqsels.com/preview/680/431/623/boy-child-kid-family.jpg",time:"2019-10-12"},
                    {"title": "简单了解保险理念", img: "https://p2.piqsels.com/preview/680/431/623/boy-child-kid-family.jpg",time:"2019-10-12"},
                    {"title": "简单了解保险理念", img: "https://p2.piqsels.com/preview/680/431/623/boy-child-kid-family.jpg",time:"2019-10-12"},
                    {"title": "简单了解保险理念", img: "https://p2.piqsels.com/preview/680/431/623/boy-child-kid-family.jpg",time:"2019-10-12"}
                ];
                setTimeout(function () {
                   $scope.listXXXX = $scope.listXXXX.concat(newData);
                   $scope.$broadcast('scroll.infiniteScrollComplete');
               },1000)
            }

        };
  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值