Home  >  Article  >  Web Front-end  >  Detailed explanation of the steps to implement pull-down refresh function in ionic

Detailed explanation of the steps to implement pull-down refresh function in ionic

php中世界最好的语言
php中世界最好的语言Original
2018-05-22 11:04:531534browse

This time I will bring you a detailed explanation of the steps to implement the pull-down refresh function in ionic. What are the precautions for ionic to implement the pull-down refresh function. The following is a practical case, let’s take a look.

<!DOCTYPE html>
<html>
 <head>
  <meta charset="utf-8" />
  <title>ionic</title>
  <!--记得导入ionic包和ionic样式-->
  <script src="js/ionic.bundle.min.js" type="text/javascript" charset="utf-8"></script>
  <link rel="stylesheet" type="text/css" href="css/ionic.css" rel="external nofollow" />
  <!--
   ionic
   angular
    $http--服务
    ng- 指令
    表达式 {{}}
   刷新案例
    ul--
    数据
  -->
 </head>
 <body ng-app="myApp" ng-controller="myCtrl">
  <ion-header-bar class="bar-calm">
   <h1 class="title">下拉刷新</h1>
  </ion-header-bar>
  <ion-content>
   <!--
    下拉刷新
    ion-refresher
     pulling-text 下拉的时候显示的文本
     pulling-icon 图标
     onRefresh 当刷新的时候调用的方法
   -->
   <ion-refresher pulling-text="松手刷新..." on-refresh = "doRefresh()" pulling-icon="img/arrow-down-c.png">
   </ion-refresher>
   <ul class="list">
    <li class="item" ng-repeat="good in goods">{{good.gname}}</li>
   </ul>
  </ion-content>
  <!--
   angular
    mvc 视图 view 各种标签,数据 ng-model{{}} ,控制器 controller 逻辑代码
    指令:一个特殊的属性
    表达式 : 一段代码 ,主要功能:取数据,可以进行运算
    模块:一些功能和视图组成的整体
    服务:就是一个方法,满足一些需要而定义的方法。内置服务30多个
      $http
    内置过滤器:9个
      管道符 |
  -->
  <script type="text/javascript">
   //创建模块
   var mod = angular.module("myApp",["ionic"]);//[]里面的是需要注入的对象。两个:ngRoute /ionic
   //创建控制器
   mod.controller("myCtrl",function($scope,$http){
    //定义数组、也就是model数据
    $scope.goods=[{"gname":"秋裤"},{"gname":"羽绒服"}];
    //刷新的方法
    $scope.doRefresh=function(){
     //请求网络,加载数据
     $http.get("data.json").then(function(req){
      //取得数据 ,req将数据封装到data属性里面了
      var d = req.data;
      //将一个集合整个加入另外一个集合contact()
//      $scope.goods= $scope.goods.contact(d);
      for (var i =0;i<d.length;i++) {
       $scope.goods.unshift(d[i]);
      }
      //结束刷新
      $scope.$broadcast("scroll.refreshComplete");
     },function(req){
      alert("失败");
     });
//     .finally(function(){
//      
//     });
    }
   });
  </script>
 </body>
</html>

I believe you have mastered the method after reading the case in this article. For more exciting information, please pay attention to other related articles on the php Chinese website!

Recommended reading:

Detailed explanation of the steps to use cookies to stay logged in

Analysis of Vue.js download method and usage steps

The above is the detailed content of Detailed explanation of the steps to implement pull-down refresh function in ionic. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn