无法多次更新范围时遇到问题

时间:2014-04-11 00:44:44

标签: ajax angularjs ionic-framework

我正在使用角度与离子框架beta 1。

这是我的ng-repeat html:

   <a href="{{item.url}}" class="item item-avatar" ng-repeat="item in restocks | reverse" ng-if="!$first">
       <img src="https://server/sup-images/mobile/{{item.id}}.jpg">
       <h2>{{item.name}}</h2>
       <p>{{item.colors}}</p>
   </a>
  </div>

这是我的controllers.js,它从XHR获取ng-repeat的数据。

   angular.module('restocks', ['ionic'])
  .service('APIservice', function($http) {

  var kAPI = {};

  API.Restocks = function() {
    return $http({
      method: 'GET', 
      url: 'https://myurl/api/restocks.php'
    });
  }

  return restockAPI;
})

  .filter('reverse', function() {
    //converts json to JS array and reverses it
      return function(input) {
        var out = []; 
        for(i in input){
          out.push(input[i]);
        }
        return out.reverse();
      }
    })

.controller('itemController', function($scope, APIservice) {
    $scope.restocks = [];
    $scope.sortorder = 'time';

    $scope.doRefresh = function() {
        $('#refresh').removeClass('ion-refresh');
        $('#refresh').addClass('ion-refreshing');
           restockAPIservice.Restocks().success(function (response) {
            //Dig into the responde to get the relevant data
            $scope.restocks = response;
            $('#refresh').removeClass('ion-refreshing');
            $('#refresh').addClass('ion-refresh');
        });
      }

      $scope.doRefresh();

  });

数据加载正常,但我希望在我的应用中实现一个刷新按钮,重新加载外部json并更新ng-repeat。当我多次调用$scope.doRefresh();时,我在JS控制台中收到此错误:

TypeError: Cannot call method 'querySelectorAll' of undefined
    at cancelChildAnimations (http://localhost:8000/js/ionic.bundle.js:29151:22)
    at Object.leave (http://localhost:8000/js/ionic.bundle.js:28716:11)
    at ngRepeatAction (http://localhost:8000/js/ionic.bundle.js:26873:24)
    at Object.$watchCollectionAction [as fn] (http://localhost:8000/js/ionic.bundle.js:19197:11)
    at Scope.$digest (http://localhost:8000/js/ionic.bundle.js:19300:29)
    at Scope.$apply (http://localhost:8000/js/ionic.bundle.js:19553:24)
    at done (http://localhost:8000/js/ionic.bundle.js:15311:45)
    at completeRequest (http://localhost:8000/js/ionic.bundle.js:15512:7)
    at XMLHttpRequest.xhr.onreadystatechange (http://localhost:8000/js/ionic.bundle.js:15455:11) ionic.bundle.js:16905

1 个答案:

答案 0 :(得分:1)

看起来它与一个错误相关,如:

https://github.com/driftyco/ionic/issues/727

引用自:

http://forum.ionicframework.com/t/show-hide-ionic-tab-based-on-angular-variable-cause-error-in-background/1563/9

我猜它几乎是同一个问题。

也许尝试使用angular.element(document.getElementById('refresh'))来寻找可能的解决方法(猜测)。