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

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

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.

share|improve this answer

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

share|improve this answer
    
Thanks for your answer, I changed the order and still not working! – Masih Aug 6 '15 at 20:46

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.