0

Following is a simple Angular.js code snippet :

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 } });
});

I am trying to implement infinite scroll using http://binarymuse.github.io/ngInfiniteScroll/

In their demo here http://binarymuse.github.io/ngInfiniteScroll/demo_basic.html they are calling the loadMore() function.

In my case i want to execute the following on scroll :

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

and increment the pageIndex Obj.PAGEINDEX = 1 by 1. How am i supposed to do that? Today is my 3rd day with Angular.js.

1 Answer 1

1

You need to implement a loadMore function like this inside your controller ,

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);
})
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.