Pregunta

I'm making my first steps trying to get data from a 3rd party API using AngularJS and Angular-resource. So far I've been able to get some data, but somehow when I try to use it in an ng-repeat, it doesn't work.

Here's my js and html:

angular.module('myApp', ['ngResource'])
function Hello($scope, $http) {
$http.get('http://api.discogs.com/artists/3823').
    success(function(data) {
        $scope.greeting = data;
    });
$http.get('http://api.discogs.com/artists/3823/releases').
    success(function(data2) {
        $scope.releases = data2;
    });
};

And HTML:

<div class="container" ng-app="myApp">
<div class="row" ng-controller="Hello">

  <p>Artist: {{greeting.name}}</p>
        <p>Real name: {{greeting.realname}}</p>



  <ul>
    <li ng-repeat="release in releases"> {{release.title}}</li>
  </ul>


   </div>  
</div>

And a Plunker. You will see that the code is taking correctly the .name and .realname, but doesn't call the releases.title for whatever reason.

What am I missing?

EDIT: I have the feeling that I'm not reading correctly the json data that comes from the API, but I don't know where the mistake is : /

¿Fue útil?

Solución

$scope.releases = data2.releases;

Check the data you got back - it's an object with two keys.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top