Stack Overflow is a community of 4.7 million programmers, just like you, helping each other.

Join them; it only takes a minute:

Sign up
Join the Stack Overflow community to:
  1. Ask programming questions
  2. Answer and help your peers
  3. Get recognized for your expertise

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

share|improve this question
1  
Show us your HTML and how do you know $scope.exportData is blank? Are you using batarang or ng-inspector? I'm guessing that you're setting $scope.exportData to your 5 item array. You're probably not implementing it right in the HTML. – VtoCorleone Jun 12 '14 at 20:18
up vote 2 down vote accepted

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;
});
share|improve this answer
    
this works....I just needed result, not result.data – user3723240 Jun 12 '14 at 20:41

missing semi-colon after result.data

can also try

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

share|improve this answer
    
$scope.exportData still appears blank at the end and I did some debugging, nothing is coming up for item – user3723240 Jun 12 '14 at 20:19
    
each array is an oject – user3723240 Jun 12 '14 at 20:29

Maybe you have problem somewhere in another place - check your browser console for errors.

Code described in question is completely valid, and it works: http://plnkr.co/edit/eKGK3R9us06AkG86zxw8

share|improve this answer
    
I checked my browser console...no errors at all – user3723240 Jun 12 '14 at 20:24
    
each array is an oject – user3723240 Jun 12 '14 at 20:25
    
can you show your markup? or how do you check that exportData is empty? – Bogdan Savluk Jun 12 '14 at 20:26
    
I know $scope.exportData is empty cause after I do a console.log on $scope.exportData – user3723240 Jun 12 '14 at 20:32
    
Where do you do console.log? if it is right after call to $http.get(...).then(...) - it will not display result, because $http works asynchronously... – Bogdan Savluk Jun 12 '14 at 20:35

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.