我正在尝试使用 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/