1

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
10
  • 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 Commented Mar 3, 2016 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 Commented Mar 3, 2016 at 16:25
  • 1
    You have not written the closing tag of tr. Commented Mar 3, 2016 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. Commented Mar 3, 2016 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 Commented Mar 3, 2016 at 16:35

2 Answers 2

1

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

Sign up to request clarification or add additional context in comments.

12 Comments

Simpler to skip the stringify ...console.log accepts multiple arguments
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
It won't when you do console.log(" values", object);. Note difference between arguments and concatenation
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.
why...easier to work with objects in console. Can see hierarchy much easier
|
0

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

use

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

or

console.log($scope.currentPageStores);

2 Comments

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.
This doesn't fix the problem in OP code and is really nothing more than a comment, not an answer

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.