Having trouble updating a scope more than once


#1

I’m using angular v1.2.12 with the ionic framework beta 1.

Here’s my ng-repeat html:

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

And here’s my controllers.js, which fetches the data for the ng-repeat from a XHR.

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

  var restockAPI = {};

  restockAPI.getRestocks = 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, restockAPIservice) {
    $scope.restocks = [];
    $scope.sortorder = 'time';

    $scope.doRefresh = function() {
    	$('#refresh').removeClass('ion-refresh');
    	$('#refresh').addClass('ion-refreshing');
    	   restockAPIservice.getRestocks().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();

  });

The data loads fine but I wish to implement a refresh button in my app that reloads the external json and updates the ng-repeat. When I call $scope.doRefresh(); more than once, I get this error in my JS console:

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

#2

Do you actually have an <ion-refresher> in your view?