I'm having difficult time displaying my JSON data from an API call I make, but I can see the response if I console log it.
My app is build up like this
angular.module('myApp', ['angularSoundManager', 'infinite-scroll'])
.controller('MovieController', function($scope, $http){
$scope.songs = [];
$scope.data = $scope.songs.slice(0, 20);
$scope.getMoreData = function () {
$scope.data = $scope.songs.slice(0, $scope.data.length + 10);
};
Function to fetch data
function fetch(){
$http.get("http://www.someAPI.com" + $scope.search + "&perpage=150")
.success(function(response){
$scope.details = response;
console.log(response);
// for loop happens here to loop through the data and push it to the empty array
for(var i=0; i < response.tracks.length; i++){
var allTracks = {
title: response.tracks[i].primary_title,
};
};
$scope.songs.push(allTracks);
}
My HTML is
<div infinite-scroll='getMoreData()' infinite-scroll-distance='1'>
<div ng-repeat="song in data">
{{song.title}}
</div>
</div>
I can see if I console.log(response)
I get Object {ID: 0, tracks: Array[150], total: 257}
On the other hand I can display my data if I use ng-repeat="song in songs"
instead. It has something to do with me assigning $scope.data
to $scope.songs
Reason why I want this to work with the slice is to be able to use infinite-scroll because I can expect from 100 to 15.000 results on my page