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 have this json data:

     {
status: "SUCCESS",
data: [
{
FirstName: "Student ",
LastName: "1",
Id: 1,
ObjectState: 0
},
{
FirstName: "Student ",
LastName: "2",
Id: 2,
ObjectState: 0
    }
   }
  ]
}

I have tried like this,in my controller and in the view: app.js:

.controller("etudCtrl",["$scope", "$http", function ($scope, $http) {
        var i;

    $http({method: 'GET', url: 'MyURL'})
             .success(function (data) {

                for(i=0;i<data.length;i++){
                $scope.paged = data[i].data; // response data 
                console.log($scope.paged+" $scope.paged");
        }
            $scope.currentPageStores= $scope.paged;
            console.log($scope.currentPageStores+"  values");

              console.log("success");
    }).error(function (data, status, headers, config) {
              console.log("data error ...");
     });
 }])

Students.html:

<table>
<thead>...</thead>
 <tbody data-ng-controller="etudCtrl">
   <tr ng-repeat="store in currentPageStores" >    
  <td align="center">{{store.LastName}}</td>
  <td align="center">{{store.FirstName}}</td>
  </tr>
</tbody>
</table>

and this what I get in console:

values
success

I didn't get any data in console or in the Table :( any help please thanks

Update: I try with this:

 $rootScope.usersData = angular.toJson(data.data);
 console.log($rootScope.usersData+" my data");

I get all the data that I want to display in console

Update2:

 $http({method: 'GET', url: 'MyURL'})
             .success(function (data) {

       console.log(JSON.stringify(data)+"myData");

        for(i=0;i<data.length;i++){
        $scope.paged = data.data[i]; // response data 
        console.log($scope.paged+" $scope.paged");
              }
.....
}

I get this in console:

{"status":"SUCCESS","data":[{"FirstName":"Student ","LastName":"1","Id":1,"ObjectState":0},{"FirstName":"Student ","LastName":"2","Id":2,"ObjectState":0}]}myData
share|improve this question
1  
can you show the log of whats being returned in success(function (data)----->whats the data here? if its object object use json stringify and log it. Can you – Alex Rumba Nicked Mar 3 at 16:22
1  
You had this set up properly in an earlier question that you must have deleted. Try $scope.currentPageStores = data.data and get rid of the loop – charlietfl Mar 3 at 16:25
1  
You have not written the closing tag of tr. – Midhun Darvin Mar 3 at 16:25
1  
Seems to me it should be data.data[i] rather then data[i].data. At least according to the shown structure. In that case for cycle should be to data.data.length. – Ivo Peterka Mar 3 at 16:25
2  
nono buddy, just the data from the success $http({method: 'GET', url: 'MyURL'}) .success(function (data) { console.log(data); whats in here --------------------> whats the data returned from the get. No need to loop around it just the plain data – Alex Rumba Nicked Mar 3 at 16:35
up vote 1 down vote accepted

No need to loop around in controller. Try the following:

Your Controller:

.controller("etudCtrl",["$scope", "$http", function ($scope, $http) {


    $http({method: 'GET', url: 'MyURL'})
             .success(function (data) {
            $scope.currentPageStores= data.data;
            console.log($scope.currentPageStores+ "  values");

              console.log("success");
    }).error(function (data, status, headers, config) {
              console.log("data error ...");
     });
 }])  

Your student.html

<table>
<thead>...</thead>
 <tbody data-ng-controller="etudCtrl">
   <tr ng-repeat="store in currentPageStores track by $index" >    
  <td align="center">{{store.LastName}}</td>
  <td align="center">{{store.FirstName}}</td>
</tbody>
</table>  

Here is a PLUNKER example of how you access when the data comes in an array as yours : http://plnkr.co/edit/Q9ewbH7XevsOQG0Yzv6B?p=preview

share|improve this answer
2  
Simpler to skip the stringify ...console.log accepts multiple arguments – charlietfl Mar 3 at 16:52
1  
just wanted to skip the part where the type of [object] [object] may come into action and i have to teach to stringify the result to OP. Thanks for the suggestion – Alex Rumba Nicked Mar 3 at 16:53
1  
It won't when you do console.log(" values", object);. Note difference between arguments and concatenation – charlietfl Mar 3 at 16:55
1  
i realized my mistake however if you just log the data.data it comes as an object and i wanted to show it as a string. – Alex Rumba Nicked Mar 3 at 16:58
1  
why...easier to work with objects in console. Can see hierarchy much easier – charlietfl Mar 3 at 17:01

You can't print a object on console with another string.

use

console.log(JSON.stringify($scope.currentPageStores)+"  values");

or

console.log($scope.currentPageStores);
share|improve this answer
    
mmm but the problem is that he is not able being able to display in the view as well. Plus i don't think your answer solves the issue. – Alex Rumba Nicked Mar 3 at 16:44
1  
This doesn't fix the problem in OP code and is really nothing more than a comment, not an answer – charlietfl Mar 3 at 16:47

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.