ionic 下拉刷新


在加载新数据的时候,我们需要实现下拉刷新效果,代码如下:

实例

HTML 代码

  1. <body ng-app="starter" ng-controller="actionsheetCtl" >
  2.     <ion-pane>
  3.         <ion-content >
  4.             <ion-refresher pulling-text="下拉刷新" on-refresh="doRefresh()"></ion-refresher>
  5.             <ion-list>
  6.                 <ion-item ng-repeat="item in items" ng-bind="item.name"></ion-item>
  7.             </ion-list>
  8.         </ion-content>
  9.     </ion-pane>
  10. </body>

JavaScript 代码

  1. angular.module('starter', ['ionic'])
  2.  
  3. .run(function($ionicPlatform) {
  4.   $ionicPlatform.ready(function() {
  5.     // Hide the accessory bar by default (remove this to show the accessory bar above the keyboard
  6.     // for form inputs)
  7.     if(window.cordova && window.cordova.plugins.Keyboard) {
  8.       cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true);
  9.     }
  10.     if(window.StatusBar) {
  11.       StatusBar.styleDefault();
  12.     }
  13.   });
  14. })
  15.  
  16. .controller( 'actionsheetCtl',['$scope','$timeout' ,'$http',function($scope,$timeout,$http){
  17.  
  18.     $scope.items=[
  19.         {
  20.             "name":"HTML5"
  21.         },
  22.         {
  23.             "name":"JavaScript"
  24.         },
  25.         {
  26.             "name":"Css3"
  27.         }
  28.     ];
  29.  
  30.     $scope.doRefresh = function() {
  31.         $http.get('http://www.shouce.ren/try/demo_source/item.json')  //注意改为自己本站的地址,不然会有跨域问题
  32.             .success(function(newItems) {
  33.                 $scope.items = newItems;
  34.             })
  35.             .finally(function() {
  36.                 $scope.$broadcast('scroll.refreshComplete');
  37.             });
  38.     };
  39. }])

item.json 文件数据:

  1. [
  2.     {
  3.         "name":"菜鸟教程"
  4.     },
  5.     {
  6.         "name":"www.shouce.ren"
  7.     }
  8. ]