L
L
leo_fr2015-09-30 18:01:01
Angular
leo_fr, 2015-09-30 18:01:01

AngularJs $http ng-repeat json?

Good time of the day, I had a problem with the output through the ng-repeat directive data in the form of a table.
HTML

<table class="table">
                            <caption></caption>
                            <thead>
                            <tr>
                                <th>№</th>
                                <th>Name</th>
                                <th>Age</th>
                                <th>Actions</th>
                            </tr>
                            </thead>
                            <tbody>
                            <tr ng-repeat="item in items">
                                <!--<td>{{user.id}}</td>-->
                                <td>{{item.name}}</td>
                                <td>{{item.age}}</td>
                                <td>
                                    <div class="btn-group" role="group">
                                        <button class="btn btn-primary btn-sm" ng-click="eEdit(item)"><i
                                                class="fa fa-pencil-square-o"></i> Edit
                                        </button>
                                        <button type="button" class="btn btn-danger btn-sm" ng-click="eDelete(item)"><i
                                                class="fa fa-trash-o fa-sm"></i> Delete
                                        </button>
                                    </div>
                                </td>
                            </tr>
                            </tbody>
                        </table>

controller.js
'use strict';

angular.module('prApp')
    .controller('efKpPdController', ['$scope', '$http',  function ($scope, $http ) {
        $http.defaults.headers.common['Content-Type'] = 'application/json; charset=utf-8';
        $http.defaults.headers.common['Accept'] = 'application/json; charset=utf-8';

        $http.post('http://symfonyapi.dev/web/app.php/show')
            .success(function(data){
                var items = data.items;

                $scope.items = data.items;
                console.log('success');
                console.log(data);
            })
            .error(function(data){
               console.log('error')
            });
    }]);

I get an array of this kind 86fbaf0092024096a5f86995573bfdb8.png
Screen from a fire bug, I can’t understand why it doesn’t assign a value
af80404d99284062aa61dfed5cb5f9c2.png
. I also noticed that there is data duplication, Thanks for the help.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
L
lega, 2015-09-30
@lega

You have a hint in the 8th and 9th lines of the last screen, data = [object, object]
Apparently you need this: 11) $scope.items = data;

D
DigitalSmile, 2015-09-30
@DigitalSmile

var items = data.items;
$scope.items = data.items;
You have data and there is an array, there are no items there.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question