ionic 下拉刷新

Ionic提供了非常简单的指令来实现下拉刷新。首先,我们需要在列表前加一个标签

<body ng-app="ionicApp">
  <ion-header-bar class="bar-energized">
    <h1 class="title">Pull to Refresh!</h1>
  </ion-header-bar>
  <ion-content ng-controller="TodosCtrl">
    <ion-refresher pulling-text="Pull to refresh" on-refresh="doRefresh()">
    </ion-refresher>
    <ion-list>
      <ion-item ng-repeat="todo in todos">{{todo.name}}</ion-item>
    </ion-list>     
  </ion-content>

</body>

我们可以定义下拉刷新时显示的字体,以及对应的操作,这里是调用doRefresh();下面我们看一下js里面怎么控制

var app = angular.module('ionicApp', ['ionic'])
 
app.controller('TodosCtrl', function($scope) {
  $scope.todos =  [
    {name: "Do the dishes"},
    {name: "Take out the trash"}
  ]
  
  $scope.doRefresh = function() {
    $scope.todos.unshift({name: 'Incoming todo ' + Date.now()})
    $scope.$broadcast('scroll.refreshComplete');
    $scope.$apply()
  };
  
})

这里我们实现上面标签里的doRefresh来更新数据,注意,在数据更新完成后要$broadcast广播一个scroll.refreshComplete的事件,这个事件是让ion-refresher知道刷新已经完成,可以隐藏自己了
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值