0

I have to show a JSON array values on a table I made with Angular JS. When I load the page calls the web service and get a JSON array. Until here everything is ok, but, when I want to show the values on the view I'm getting nothing. I did it like I did it previously and don't know why it's not working.

There is the controller:

assets.controller('DetallTipusCtrl', function ($scope, $http, $routeParams){
                $http.get('http://10.0.203.73/WS/ws.php/tipusactius/getDetails/'+$routeParams.param).success(function(data) {
                    $scope.atrb = data;
                });
                $scope.param = $routeParams.param;    
            });

And the view:

<table class="table" ng-controller="DetallTipusCtrl">
                    <tr>
                        <th>#</th>
                        <th><a href="">Atribut</a></th>
                        <th><a href="">Mida</a></th>
                        <th><a href="">Tipus</a></th>
                    </tr>
                    <tr ng-repeat="atribut in atrb | orderBy:sortField:reverse">
                        <td></td>
                        <td>{{atribut.nomAtribut}}</td>
                        <td>{{atribut.midaAtribut}}</td>
                        <td>{{atribut.valor}}</td>
                    </tr>
                </table> 

The JSON array is well constructed but I can't see nothing and I don't know why, if anyone can help.. Thanks!

Edit: The JSON:

{"nomAtribut":"fgdsgsfd","midaAtribut":"16","valor":"String","tipus_actius_idtipus_actius":"26","nom":"yiuhdfiau837629875wf"}

Solved:

The JSON array was a JSON object, thats how I iterate over and show properties:

<tr ng-repeat="(key, value) in atrb">
    <td>{{value.propertie}}</td>
</tr>
9
  • 1
    can we see the json? Commented Mar 9, 2016 at 9:41
  • @EuphoriaGrogi I just added Commented Mar 9, 2016 at 9:44
  • there is no sortfield property in your json Commented Mar 9, 2016 at 9:44
  • @EuphoriaGrogi I removed the sortfield and still don't work Commented Mar 9, 2016 at 9:46
  • 1
    do your response is successful? Commented Mar 9, 2016 at 9:46

4 Answers 4

3

Your response is not an array, its an object. You can iterate over object properties like this:

<tr ng-repeat="(key, value) in atrb">
    <td>{{value}}</td>
</tr>

If you need to show properties conditionally you can check the key.

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

2 Comments

With your solution I see the JSON array into the table cell
Yes it's working fine now I missed the properties on the view. Thank you!
0

You should do this in your success function

    $http.get('http://10.0.203.73/WS/ws.php/tipusactius/getDetails/'+$routeParams.param).success(function(data) {

   $scope.$evalAsync(function(){$scope.atrb = data;});

});

Comments

0

your response is not an array

        <td>{{atrb.nomAtribut}}</td>
         <td>{{atrb.midaAtribut}}</td>
         <td>{{atrb.valor}}</td>

to display use above code

Comments

0

make $http call like :

$http.get('http://10.0.203.73/WS/ws.php/tipusactius/getDetails/'+$routeParams.param)
.then(function(response) {$scope.atrb = response.data;});

Comments

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.