不能使用AngularJS从DRF页面显示的信息 [英] Cannot show information from DRF page using AngularJS
本文介绍了不能使用AngularJS从DRF页面显示的信息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
下面是codeS,我已经写了:
Here are the codes that I've written:
DRF页 [的http://本地主机:8000 /指数/信息/?格式= json的]
[{"id": 1, "name": "Michel", "city": "Florida", "country": "United States"}, {"id": 2, "name": "Shuvo", "city": "London", "country": "United Kingdom"}]
2.HTML [这是我的第二次尝试]
2.html [this is my second attempt]
<!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页面显示什么。这是完全空白的。我究竟做错了什么? (
My 2.html page shows NOTHING. It's completely blank. What am I doing wrong? :(
推荐答案
我怀疑它的东西做的数据格式
I suspect it's something to do with the format of the data being returned in
$http.get("http://localhost:8000/index/info/?format=json")
什么是你在控制台中看到http.get运行时?
What are you seeing in the console when http.get runs?
下面是显示它plunkr与您的数据的工作。
Here's a plunkr showing it working with your data
http://plnkr.co/edit/x0OtVbsnSMk3mdhRFEkc
这篇关于不能使用AngularJS从DRF页面显示的信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文