【发布时间】:2013-09-10 04:47:54
【问题描述】:
我正在尝试使用 Angular js $get 来获取数据。我可以用这样的简单功能来做到这一点:
<script>
$(document).ready(function() {
$.getJSON('{% url 'ajax-view' %}', function(data) {
alert(data['revenue']);
})
})
</script>
but trying this way in angular. since im new to this. cant get it work.
<script>
var app = angular.module('plinc', []);
app.controller('MainCtrl', function($scope, $http) {
$http({
url: '{% url 'ajax-view' %}',
method: "GET"
}).then($scope.getdata = function(response) {
alert(data['revenue']);
$scope.data = response;
});
});
</script>
这里是完整的 django 模板:https://dpaste.de/4Y3y5/
【问题讨论】:
-
使用 Django 模板和 Angular 对我来说似乎不是一个好主意:(。你可以用 Angular 模板完全替换 Django MTV 中的模板。
标签: javascript django angularjs