user3723240
user3723240

Reputation: 393

angular JS $http.get returns array, trying to put each array in $scope

I am using this $http.get call in my angular JS:

$scope.exportData = [];

$http.get('/reports?UserId=1').then(function (result) {
       $scope.exportData = result.data
});

$scope.exportData returns blank :(

but when I debug this I see that result.data is getting populated and result.data has 5 arrays in it...my question is how would I put each of those arrays in $scope.exportData result.data has a length value of 5. Maybe I could use that to do a foreach? I would know how to do that in php by javascript/jquery/angular js I am a newbie. Any help would be much appreciated.

Here is a screenshot on what gets populated for results.data:

enter image description here

Thanks, J

Upvotes: 0

Views: 2326

Answers (2)

jmbmage
jmbmage

Reputation: 2547

missing semi-colon after result.data

can also try

angular.forEach(result.data, function(item) {
  // set a break point here:
  $scope.exportData.push(item);
});

Upvotes: 1

possiblyLethal
possiblyLethal

Reputation: 191

Perhaps the nested function is not getting called. $http.get([url]) is a valid shortcut and thus may be populating result.data, however you do not specify the success or failure call backs.

Perhaps try:

$http.get('/reports?UserId=1').success(function (result) {
     $scope.exportData = result;
});

Upvotes: 2

Related Questions