Ruben Alonzo Ruben Alonzo - 5 months ago 11
HTML Question

How do I use this format of JSON in ng-repeat

This is the JSON and controllers im using:

JSON Format:

{"networks":[{"longName":"lo"},{"longName":"eth0"}]}


Factory:

app.factory('networkFactory', [ '$http',
function($http) {
return $http.get("http://localhost:8080/JAXRS-RESTEasy/rest/toolservice/network")
.success(function(data) {
return data;
}).error(function(err) {
return err;
})
} ]);


Controller:

app.controller('networkController', [ '$scope', 'networkFactory',
function($scope, jsonFactory) {
jsonFactory.success(function(data) {
$scope.network = data;
});
}]);


HTML:

<div ng-controller="networkController">
<table class="table">
<tr ng-repeat="x in network">
<td>{{x.longName}}</td>
<tr>
</table>
</div>


So i tried this, and the names don't appear they seem to not get loaded into the html.

What I'm I doing wrong, is the word "networks" in front of the JSON affect the way i need to read the JSON?

Thank you.

Answer

Here is the plunker http://plnkr.co/edit/x0zCgzNGggBueBFlg0H5?p=preview

var app=angular.module('myApp',[])
app.factory('networkFactory', [ '$http', 
                                    function($http) {
                                        return $http.get("tag.json")
                                            .success(function(data) {
                                                return data;
                                            }).error(function(err) {
                                                return err;
                                            })

                                        } ]);


                                        app.controller('networkController', [ '$scope', 'networkFactory',
                                        function($scope, networkFactory) {
                                            networkFactory.success(function(data) {
                                              debugger
                                                    $scope.network = data.networks;
                                    });
                                }]);