无法使用AngularJS显示DRF页面中的信息

时间:2015-06-03 21:36:55

标签: angularjs django rest controller frameworks

以下是我编写的代码:

DRF页面 [http://localhost:8000/index/info/?format=json]

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

2.html [这是我的第二次尝试]

<!DOCTYPE html>

<html>
<script src="angular.min.js"></script>
<script src="2.js"></script>
<body>
<div ng-app="myApp" ng-controller="myCtrl">
    <ul>
        <li ng-repeat="x in info">
            {{ x.name + ', ' + x.country }}
        </li>
    </ul>
</div>
</body>    
</html>

2.js

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

app.controller('myCtrl', function($scope, $http) {
    $http.get("http://localhost:8000/index/info/?format=json")
    .success(function(response) {
        $scope.info = response;
    });
});

我的2.html页面显示没有。它完全是空白的。我究竟做错了什么? :(

2 个答案:

答案 0 :(得分:0)

由于django和angular使用相同的符号来显示变量,因此您必须使用verbatim tags{{}}用作角度标记。否则它们将被视为django标签。

答案 1 :(得分:0)

我怀疑它与

中返回的数据格式有关
$http.get("http://localhost:8000/index/info/?format=json")

当http.get运行时,您在控制台中看到了什么?

这是一个使用数据的傻瓜

http://plnkr.co/edit/x0OtVbsnSMk3mdhRFEkc