google feed api get 10 entries at a time load more with next

494 Views Asked by At

I am using the google feed api to create an rss reader but I do not want all the data up front I want 10 entries, when the user clicks load more I want to load the next 10 and so on.

The code I am using gets all the entries and in the documentation I was not able to figure out how to achieve this.

http://ajax.googleapis.com/ajax/services/feed/load?v=2.0&q=http://rss.cnn.com/rss/cnn_topstories.rss&num=5
 .factory('rssReader', ['$http', function($http) {
return $http.get('URL_HERE')
.success(function(data) {
  alert("SUCCESS!!!" + data);//return data;
})
.error(function(data) {
  alert("FAILED!!!!" + data);//return data;
 });
}]);

Is this possible?

Is there any other api that provides this?

1

There are 1 best solutions below

1
user2932428 On

try this :)

var app = angular.module('myApp', []);
app.controller('rssCtrl', function($scope, $http, $sce) {
  var rssUrl = 'http://rss.cnn.com/rss/cnn_topstories.rss',
    num = 10;

  function getFeed() {
      $http.jsonp('https://ajax.googleapis.com/ajax/services/feed/load?v=1.0&num=' + num + '&q=' + rssUrl + '&callback=JSON_CALLBACK')
        .success(function(data) {
          $scope.entries = data.responseData.feed.entries;
        });
    }
    //init call
  getFeed();

  $scope.to_trusted = function(html_code) {
    return $sce.trustAsHtml(html_code);
  }
  $scope.more = function() {
    num += 10;
    getFeed();
  }
});
<div ng-app="myApp" ng-controller="rssCtrl">
  <div ng-repeat="entry in entries">
    <h2><a href="{{entry.link}}">{{entry.title}}</a></h2>
    <p ng-bind-html="to_trusted(entry.content)"></p>
  </div>
  <button ng-click="more()">Load more</button>
</div>
<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.4.4/angular.min.js"></script>