Quantcast
Channel: Ionic Forum - Latest posts
Viewing all articles
Browse latest Browse all 228595

Infinite scroll with http post

$
0
0

Hi

I am trying to create an infinite scroll based on Gajotres post (http://www.gajotres.net/ionic-framework-tutorial-11-infinite-scroll/)

My problems are:

If i write : $scope.searchObjects($scope.formData); all $scope objects are printed on the screen, how can it be avoided?

Can i pass form data by using $scope.formData, this way: .
$scope.searchObjects($scope.formData);

until now the list freezes with 7000 itens and can not get the infinite scroll to work , seems it load all the itens.

Here is my attempt code any help would be apreciated :

.controller('someObjectsCtrl', function( $scope, $http) {
 $scope.data = null;
 $scope.itens = [];
  $scope.data = {
    'state'  : '',
    'city'  : '',
  }
  $http.get('http://someservice.com/states.php').then( function response(response){
        $scope.states = response.data;
    },function(error){
        $scope.error = JSON.stringfy(error);
  });

  $scope.getCities = function(id) {
    $http.get('http://someservice.com/state.php?stateid='+id).then( function response(result) {
          $scope.cities = result.data;
          $ionicLoading.hide();
      },function(error) {
          $scope.error = JSON.stringfy(error);
      });
    };
  $scope.originForm = angular.copy($scope.data);
  $scope.searchObjects = function(data) {
    $scope.formData = {};
    $scope.formData.state = data.state;
    $scope.formData.city  = data.city;
    $http.post("http://someservice.com/objectsToSearch.php", $scope.formData )
      .success( function(data) {

          $scope.result  = data;

          for (var i = 0; i <= 6; i++) {
            $scope.itens.push({ foundObjects: $scope.result.OBJECTS});
          }
          $scope.$broadcast('scroll.infiniteScrollComplete');

          if( $scope.result.length == 0 ){
            $scope.data = null;
          }
          $scope.headers = ['Some Objects', 'Another Objects' ];
     })
    .error(function(error){
      $ionicLoading.show({ template: '<p>Error ...</p>',duration :6000  });
    })
  }
  $scope.canWeLoadMoreContent = function() {
    return ($scope.itens.length > 10) ? false : true;
    console.log(' scope.itens.length '+$scope.itens.length );
  }
  $scope.searchObjects($scope.formData);
})

Viewing all articles
Browse latest Browse all 228595

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>