离子刷新未进入功能

时间:2017-08-14 06:15:56

标签: javascript ionic-framework

我正在开发一个Ionic 1项目,我正在调用API来检索数据。但离子刷新似乎没有按预期工作。它不会进入刷新时应该具有的功能。这是我的代码:

HTML code:

<ion-view view-title="Hotels" ng-controller="AgHotelCtrl">
  <ion-content>
<ion-refresher pulling-text="Pull to refresh..." on-refresh="init()">
</ion-refresher>
<ul class="list">
    <li ng-repeat="r in res" class="item">
      <h2>{{r.name}}</h2>
      <p>{{r.locality}}</p>
    </li>
</ul>
 </ion-content>
</ion-view>

JS代码:

.controller('AgHotelCtrl', function($scope, $state) {
 var init = function() {
console.log("hola");
var user = $state.params.user;
$scope.res=[];
var whereClause = "agent_email = '" + user.email + "'";
var queryBuilder = Backendless.DataQueryBuilder.create().setWhereClause( whereClause );
Backendless.Data.of("Hotels").find( queryBuilder )
  .then(function(foundHotels) {
    $scope.res = foundHotels;
  })
  .catch(function(error) {
    console.log("error" + error.message);
  })
 }
 init();
})

1 个答案:

答案 0 :(得分:0)

on-refresh="init()"查找$scope.init()方法。但是,您的本地init未绑定到$scope

修正:

我会将init更改为doRefresh

<ion-refresher pulling-text="Pull to refresh..." on-refresh="doRefresh()">

在控制器中添加:

$scope.doRefresh = function(){
 init();
}