使用Angularjs显示JSON响应

时间:2017-10-25 17:05:48

标签: angularjs json get

我需要使用Angularjs显示来自JSON响应的数据

当使用DevTools检查响应时,我可以看到结果,但是当涉及到diplay时,它不起作用

控制器:

MovieApp.controller('movieAdminCtrl',  ['$http', '$scope', function($http, $scope){
    $scope.movies=[];
    $http.get('http://localhost:3000/movies').success(function(data) {
        $scope.movies = data;

    }); 

        }]);

回应: enter image description here

显示代码:

 <tbody ng-repeat="movie in movies"  >
                <td></td>

                <td >{{movie.title}}</td>
                <td >{{movie.actors}}</td>
                <td >{{movie.Created_date}}</td>
                <td><img ng-src="{{movie.poster}}" /></td>

2 个答案:

答案 0 :(得分:2)

您需要访问回复的 data 属性

 $http.get('http://localhost:3000/movies').success(function(data) {
        $scope.movies = data.data;
 }); 

答案 1 :(得分:0)

请尝试此代码..

<!DOCTYPE html>
<html>
<head>
    <title></title>
    <meta charset="utf-8" />
</head>
<body ng-app="app" ng-controller="movieAdminCtrl">

    <table>
        <tr ng-repeat="movie in movies">
            <td></td>

            <td>{{movie.title}}</td>
            <td>{{movie.actors}}</td>
            <td>{{movie.Created_date}}</td>
            <td>
                <img ng-src="{{movie.poster}}" />
            </td>
        </tr>
    </table>

    <script src="../lib/angular.js"></script>
        <script>
            var MovieApp = angular.module('app', []);
            MovieApp.controller('movieAdminCtrl', ['$http', '$scope', function ($http, $scope) {
                $scope.movies = [];
                $http.get('http://localhost:3000/movies').success(function (data) {
                    $scope.movies = data;

                });

            }]);
        </script>
</body>
</html>