javascript - How to retrieve and append data using the same web api get request in Angularjs -


here using "$http.get" request retrieve data web api in angular.js.

an api url has parameter call "pageno=" , it's require add digit @ end of parameter retrieve data of respective page number maintain heavy request loads, each page has 10 list of records.

i took scope variable ($scope.pagecount) , pass url, it's working fine , able retrieve 10 list of records @ once.

now suppose rest of data on scroll down (like using infinite-scroll) , append existing list of data.

is possible or way retrieve more data same request? have added 'infinite-scroll' application , getting alert on scroll down.

following current working function.

app.controller('spotlightctrl', function ($scope, $http, shareeventid) {      $scope.pagecount = 1;     $http.get("https://stg.myapi.svc/pageno="+$scope.pagecount+)       .then(function (response) {           $scope.data = response.data;            $scope.loadmore = function () {               alert('load more records');           };        });  }); 

and html code:

<div class="content-block spotlight-listing" ng-controller="spotlightctrl" infinite-scroll='loadmore()' infinite-scroll-distance='1'>     <h1>spotlight</h1>     <div ng-repeat="event in data.eventlist" class="deals-block">         <div class="col-md-4 col-xs-12 img-style">             <a href="/spotlight-detail"><img ng-src="{{event.eventposterimage}}" class="img-responsive img-rounded" /></a>         </div>     </div> </div> 

please share if details not clear, appreciated...

you can put http call in function , call function pagecount.

app.controller('spotlightctrl', function ($scope, $http, shareeventid) {   $scope.pagecount = 1;  $scope.data = [];  function getdata() {     $http.get("https://stg.myapi.svc/pageno=" + $scope.pagecount)         .then(function (response) {             $scope.data = $scope.data.concat(response.data);         });  }   $scope.loadmore = function () {     console.log('loading more records');     ++$scope.pagecount; //page count incremented 1,     getdata();  };   getdata(); }); 

when loadmore function called pagecount incremented 1 , next records appended $scope.data


Comments

Popular posts from this blog

javascript - Clear button on addentry page doesn't work -

c# - Selenium Authentication Popup preventing driver close or quit -

tensorflow when input_data MNIST_data , zlib.error: Error -3 while decompressing: invalid block type -