1

I need to display data from JSON response using Angularjs

When checking the response with DevTools i can see the results, but when it comes to diplay, it doesn't work

Controller :

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

    }); 

        }]);

Response : enter image description here

Display Code :

 <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>
1
  • can you pls post the complete html and angular code? may be something very small is missing Commented Oct 25, 2017 at 17:23

2 Answers 2

2

You need to access the data property of the response

 $http.get('http://localhost:3000/movies').success(function(data) {
        $scope.movies = data.data;
 }); 
Sign up to request clarification or add additional context in comments.

4 Comments

post what you see inside $scope.movies .
How can i sse inside ? i tried with an alert just after $scope.movies = data.data; but nothing happen
console.log (JSON.stingify(data)); and post here
Thanks it's working now it was a CORS problem with the api
0

Please try this code..

<!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>

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.