我在使用 Angularjs 在网页上显示 JSON 响应时遇到问题,在 DevTools 上,我可以看到 GET 请求工作得很好并且可以获取所有数据,但是当涉及到在列表上显示它时,我得到的只是点.
我的 Controller :
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>
我尝试使用警报进行调试,我发现我的 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">
关于javascript - JSON 响应未在 Angularjs View 中显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46862776/