REST Corner Utility


I need to encode an AngularJS page that displays some JSON data coming from a REST service. The REST service, when invoked, displays JSON sample data:

[{"key":"ABX1234","value":"Network Hub"}]

Here is the HTML page that I use to retrieve the data:

<html ng-app>
    <head>
    <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.0.8/angular.min.js"></script>
        <script>
        function Hello($scope, $http) {
            $http.get('http://host/json').
                success(function(data) {
                    $scope.json = data;
                });
        }
        </script>
    </head>
    <body>
        <div ng-controller="Hello">
            <p>The ID is {{json.key}}</p>
            <p>The content is {{json.value}}</p>
        </div>
    </body>
</html>

Unfortunately, nothing is displayed as json.key or json.value. Can you help me figure out what the problem is?
Thank!

+4
source share
1 answer

It should be like this:

 <div ng-controller="Hello">   
    <div ng-repeat="json in json">
                <p>The ID is {{json.key}}</p>
                <p>The content is {{json.value}}</p>
    </div>
</div>

You get an array of objects. It must be repeated.

+3
source

Source: https://habr.com/ru/post/1531898/


All Articles