I use Google Feed API with AngularJS but it dosen't work!

136 views
Skip to first unread message

Randy

unread,
Jan 21, 2014, 8:09:55 PM1/21/14
to ang...@googlegroups.com
<html ng-app="feed">
<head>

<script type="text/javascript" src="bower_components/angular/angular.min.js"></script>
<script type="text/javascript" src="bower_components/storedb/storedb.js"></script>
<script type="text/javascript" src="https://www.google.com/jsapi"></script>
<script>
google.load("feeds","1")
var ggrss = (function(){
      var cache = [];
      
      return {
        parse: function(url,num,callback){
 
          function initialize() {
            var feed = new google.feeds.Feed(url);
            feed.setNumEntries(num);
            feed.load(function(result) {
              if (!result.error) {
                for (var i = 0; i < result.feed.entries.length; i++) {
                  var entry = result.feed.entries[i];
                  cache.push(entry)
                }
                callback(result.error,cache)
              }
            });
          }
          google.setOnLoadCallback(initialize);
        },
 
      }
}())

</script>
<script type="text/javascript">


var app = angular.module('feed',[]);
app.controller('feedCtrl',function($scope){
  $scope.feedList = storedb('feed').find()
  $scope.addFeed = function(feedName,feedURL){
    storedb('feed').insert({"feedName":feedName,"feedURL":feedURL},function(err,res){
      $scope.feedList = storedb('feed').find()
    })
  }

  $scope.showTitle = function(){
    ggrss.parse('http://36kr.com/feed',4,function(err,res){
      alert('a')
    })
  }
})

</script>


<body ng-controller="feedCtrl">
  <div>
    <input ng-model="feedName" placeholder="Feed Name" />
    <input ng-model="feedURL" placeholder="Feed URL" />
    <button ng-click="addFeed(feedName,feedURL)">Add</button>
    <ul ng-repeat="feed in feedList">
      <li><a ng-click="showTitle()">{{feed.feedName}}</a></li>
    </ul>
  </div>
  <div>
    <ul ng-repeat="feed in feeds">
      <li>{{feed.title}}</li>
    </ul> 
  </div>
</body>
</html>

Is there anything wrong in the ggrss function? Or it is the matter with AngularJS?

Sander Elias

unread,
Jan 22, 2014, 2:19:58 AM1/22/14
to ang...@googlegroups.com
Hi Randy,

With questions like those, you really should build an plunk or fiddle do demonstrate your problem.
As far as I can see it now, it is wrong in the ggrss function. It looks like it is not returning what it should.

Regards
Sander

Randy Lu

unread,
Jan 23, 2014, 6:50:12 AM1/23/14
to ang...@googlegroups.com
But i had tried to use ggrss without angular, it works
--
You received this message because you are subscribed to a topic in the Google Groups "AngularJS" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/angular/8pmp3sVUXfM/unsubscribe.
To unsubscribe from this group and all its topics, send an email to angular+u...@googlegroups.com.
To post to this group, send email to ang...@googlegroups.com.
Visit this group at http://groups.google.com/group/angular.
For more options, visit https://groups.google.com/groups/opt_out.

Sander Elias

unread,
Jan 23, 2014, 8:41:56 AM1/23/14
to ang...@googlegroups.com
Randy,

Make it into a plunk/fiddle and some of us are willing to take a serious look at it. 
If you want to have a go at it yourself, put in some console.log's in the ggrrs function, or have a look in the debugger what is going on.

Regards
Sander
Reply all
Reply to author
Forward
0 new messages