0

I have made a simple DRF page with the following output:

[
    {
        "id": 1, 
        "name": "Michel", 
        "city": "Florida", 
        "country": "United States"
    }, 
    {
        "id": 2, 
        "name": "Hasan", 
        "city": "London", 
        "country": "United Kingdom"
    }
]

I have the following code in HTML:

<script src="angular.min.js"></script>

<div ng-app="myApp" ng-controller="myCtrl">
    <ul>
        <li ng-repeat="x in info">
            {{ x.name + ', ' + x.country }}
        </li>
    </ul>
</div>

I have the following in a .js file:

var app = angular.module('myApp', []);

app.controller('myCtrl', function($scope, $http) {
    $http.get("localhost:8000/index/info/")
    .success(function(response) {
        $scope.info = response[array name was supposed to go here];
});

The tutorial that I am following is this, which has the whole data in a an array with an array name. They used the name after response, see the .js file code. My question is, how can I give a name to my array, or call this array without a name?

6
  • Go through this thinkster.io/django-angularjs-tutorial Commented Jun 3, 2015 at 14:14
  • blog.kevinastone.com/… Commented Jun 3, 2015 at 14:14
  • stackoverflow.com/questions/27282360/… Commented Jun 3, 2015 at 14:15
  • I have gone through these links guys. I think if I just figure my code out I can be confident to follow those tutorials. I feel that they are a bit too advanced for me. Commented Jun 3, 2015 at 15:24
  • It's unclear for me what you're trying to accomplish. Could you add some pseudo-code of the desired state? Commented Dec 1, 2015 at 20:17

1 Answer 1

0
    $scope.projects = [];
$http.get('/api/projects/').success(function(data) {
    $scope.projects = data;
    console.log($scope.projects);

});

Source: Django and AngularJS - Sending query JSON data to Angular

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

2 Comments

Tried this. The page tries loading for a long time and then it shows The webpage is not available. Same problem as before.
Made a mistake with the URL. Now it just shows {{ x.name + ', ' + x.country }}. :-/

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.