Javascript JSON响应未在带有Angularjs的视图上显示
我在使用Angularjs在网页上显示JSON响应时遇到问题,在DevTools上,我可以看到GET请求工作得很好,可以抓取所有数据,但是当要在列表上显示它时,我得到的只是点 我的控制器:Javascript JSON响应未在带有Angularjs的视图上显示,javascript,angularjs,json,node.js,Javascript,Angularjs,Json,Node.js,我在使用Angularjs在网页上显示JSON响应时遇到问题,在DevTools上,我可以看到GET请求工作得很好,可以抓取所有数据,但是当要在列表上显示它时,我得到的只是点 我的控制器: budgetApp.controller('DepensesListCtrl', ['$scope', '$http', function DepensesListCtrl($scope, $http) { $scope.depenses = [];
budgetApp.controller('DepensesListCtrl', ['$scope', '$http',
function DepensesListCtrl($scope, $http) {
$scope.depenses = [];
$http.get('http://localhost:3000/api/depenses', {withCredentials: true}).success(function(data) {
$scope.depenses = data;
});
使用ng repeat:
<div >
<div class="jumbotron text-center">
<h1>depenses Page</h1>
</div>
<ul ng-repeat="depense in depenses">
<li>{{depense.depname}}</li>
<li>{{depense.depcat}} </li>
</ul>
结果:
响应JSON:
我尝试使用警报进行调试,我发现我的depenses数组始终提供未定义的您的数据是一个具有属性Depense的对象,其中包含要重复的数组 尝试: 或:
$http.get('http://localhost:3000/api/depenses', {withCredentials: true}).success(function(data) {
$scope.depenses = data.Depense;
// ^^^ property that contains array
});
<ul ng-repeat="depense in depenses.Depense">