0

I am trying to show the data coming from a server, I tried to make a controller and copy the response to a property of scope. I tried 'response' and 'response.data' and none of them worked.

the html file looks like this:

<!DOCTYPE html>
<html>
<head>
    <script src="angular.min.js"></script>
    <title>Service Call ...</title>
</head>

<body>
    <script>
        var app = angular.module('myApp', []);

        app.controller('customersCtrl', function($scope, $http) {
            $http.get("https://linkToServer.json")
                .success(function(response) {$scope.trainings = response.data;
            });
        });
    </script>

    <div ng-app="myApp" ng-controller="customersCtrl">  
        <ul>
            <li ng-repeat="tr in trainings">
                {{ tr.id }}
            </li>
        </ul>
    </div>
</body>
</html>

The json structure is something like:

[
  {
    "id" : "sm1001",
    "name" : "Lu",
  },
{
    "id" : "lm9898",
    "name" : "Di",
  },
  ....
]

What is wrong?

Plunkr of the problem

5
  • 1
    have you tried .success(function(response) {$scope.trainings = response; ? Commented Aug 6, 2015 at 20:22
  • @Vineet he already tried that..do read question carefully Commented Aug 6, 2015 at 20:23
  • 1
    The remote file is served over https. Is your script too? Commented Aug 6, 2015 at 20:24
  • I beg your pardon @PankajParkar I will keep it in mind for the next time. Commented Aug 6, 2015 at 20:27
  • 1
    Look at the network tab in your browser's debugger console, I bet you'll find an error there. Commented Aug 6, 2015 at 20:31

2 Answers 2

1

Your plunk worked when I corrected the json. You did not include the json in the sample. I copied it from your question.

"name" : "Lu",

needs to be

"name" : "Lu"

http://plnkr.co/edit/toSicojh58y1lWrziyI8?p=preview

This might be only your sample data. The angular code is working fine.

Sign up to request clarification or add additional context in comments.

Comments

0

I think it's because your html is all messed up. First a div, then a head tag I've updated your plunkr, now it's working: http://plnkr.co/edit/6Y1dX9vKkDANdZyEd0aj?p=preview

1 Comment

Thanks for your answer, I changed the order and still not working!

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.