2017  Kodetalk | Feedback | Privacy Policy | Terms | About
userimage

Using ng-repeat on a JSON object doesn't work - why?

I can"t seem to iterate over a JSON object using ng-repeat. I did test it directly by index and it works, but just can"t seem to loop and print. What am I doing wrong?

Here"s my code:

<div ng-app="myApp">  
<div ng-controller="Ctrl">  
     <h3>Upcoming Events</h3>     
     <ul ng-repeat="event in events">         
        <li>{{ event.feed.entry.title.$t }}</li>            
     </ul>     
 <!-- testing single entry here - it works! -->    
 <small>{{ events.feed.entry[0].title.$t }}</small> 
 </div>
 </div>

The script:

var app = angular.module("myApp", []); 
var feedUrl = "https://www.google.com/calendar/feeds/ogmda.com_89pas0l9jbhpf053atd83hdj30%40group.calendar.google.com/publi                c/basic?alt=json";  
app.controller("Ctrl", function($http, $scope) {
     $http.get(feedUrl).success(function(data) {  
           $scope.events = data;    
     });
 });
userimage
That's because you iterate over the whole data returned by the calendar query, and not over the entries themselves. Change your ul to:

<ul ng-repeat="entry in events.feed.entry">
    <li>{{ entry.title.$t }}</li>    
</ul>


Answer is