1

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 : /

1
  • StuR, already tried (actually u're right, i'll edit and change it as it is wrong) but same issue... Commented Mar 12, 2014 at 15:13

1 Answer 1

1

$scope.releases = data2.releases;

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

Sign up to request clarification or add additional context in comments.

2 Comments

Brilliant! And taking a bit of advantage, the json response is in this format: 3: {status:Accepted, thumb:api.discogs.com/image/R-150-54977-1158758835.jpeg, title:Uniform,…} artist: "Alva Noto + Scanner" format: "CD, MiniAlbum" id: 54977 label: "SFMOMA" resource_url: "api.discogs.com/releases/54977" role: "Main" status: "Accepted" thumb: "api.discogs.com/image/R-150-54977-1158758835.jpeg" title: "Uniform" type: "release" year: 2001 How could I filter it by role? Eg. if role="Main"?
ng-repeat="release in releases | filter: { role: 'Main' }" Read more about filters here: docs.angularjs.org/api/ng/filter/filter

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.