0

I'm having trouble accessing the artists array within the items array here to be able to render the name field:

enter image description here

I'm currently able to grab other values at the same level as the artists that are simple objects. How can I loop through the array of the nested array?

Controller

$scope.search = "";
$scope.listLimit = "10";
$scope.selectedSongs = [];
$scope.addItem = function(song){
    $scope.selectedSongs.push(song);
}

function fetch() {
  $http.get("https://api.spotify.com/v1/search?q=" + $scope.search + "&type=track&limit=50")
    .then(function(response) {
      console.log(response.data.tracks.items);
      $scope.isTheDataLoaded = true;
      $scope.details = response.data.tracks.items;
    });
}

Template

<div class="col-md-4">
  <div class="playlist">
    <h3>Top 10 Playlist</h3>
    <ul class="songs" ng-repeat="song in selectedSongs track by $index | limitTo: listLimit">
        <li><b>{{song.name}}</b></li>
        <li>{{song.artists.name}}</li>
        <li contenteditable='true'>Click to add note</li>
        <li contenteditable='true'>Click to add url for image</li>
    </ul>
    <div id="result"></div>
  </div>
</div>
0

1 Answer 1

1

You should do another ng-repeat to access the artists,

<div class="songs" ng-repeat="song in selectedSongs track by $index | limitTo: listLimit">
<ul ng-repeat="artist in song.artists">
        <li><b>{{song.name}}</b></li>
        <li>{{artist.name}}</li>
        <li contenteditable='true'>Click to add note</li>
        <li contenteditable='true'>Click to add url for image</li>
</ul>
</div>
Sign up to request clarification or add additional context in comments.

Comments

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.