2014-03-19 159 views
0

下面的函数是一个简单的Angular.js代码片段:调用从Angular.js控制器

XApp.controller('ProductsController', function ($scope, GetProductsForIndex, $http) { 
    console.log('Step 1'); 
    var Obj = new Object(); 

    Obj.PAGEINDEX = 1; 
    Obj.PAGESIZE = 25; 
    Obj.SPNAME = "index_get_products"; 
    Obj.PAGECOUNT = null; 
    Obj.COUNTRYCODE = 'in' 

    $scope.data = GetProductsForIndex.query({ parameters : Obj }, function() { 
     console.log($scope.data); 
     $scope.products = $scope.data; 
    }); 

}) 


XApp.factory('GetProductsForIndex', function ($resource) { 
    console.log('Step 2'); 
    return $resource('api/index/:object?type=json', {}, { 'query': { method: 'GET', isArray: true } }); 
}); 

我试图用http://binarymuse.github.io/ngInfiniteScroll/

在他们的演示这里http://binarymuse.github.io/ngInfiniteScroll/demo_basic.html他们实现无限滚动调用loadMore()函数。

在我的情况,我想执行下列上滚动:

$scope.data = GetProductsForIndex.query({ parameters : Obj }, function() { 
      console.log($scope.data); 
      $scope.products = $scope.data; 
     }); 

,并增加由1. PageIndex的Obj.PAGEINDEX = 1我应该怎样做呢?今天是我与Angular.js的第三天。

回答

1

你需要实现这样的功能loadMore你的控制器内,

XApp.controller('ProductsController', function ($scope, GetProductsForIndex, $http) { 
    function loadData($scope, obj){ 
      $scope.products.push(GetProductsForIndex.query({ parameters : Obj }, function()      {   

      })); 
    } 

console.log('Step 1'); 
    var Obj = new Object(); 
    $scope.products=[]; 
    Obj.PAGEINDEX = 1; 
    Obj.PAGESIZE = 25; 
    Obj.SPNAME = "index_get_products"; 
    Obj.PAGECOUNT = null; 
    Obj.COUNTRYCODE = 'in' 

    loadData($scope, Obj); 
}) 
+0

谢谢,它的工作。 – Monodeep