如何使用 AngularJS 循环此数据?
在 Laravel 中,我可以在 HTML 中执行 var_dump,但我不熟悉 Angular。有关调试的任何建议以及如何循环它?
.controller('FeedEntriesCtrl', function($scope, $stateParams, $http, FeedList, $q, $ionicLoading, BookMarkService) {
$scope.feed = [];
$scope.doRefresh = function() {
$http.get("http://www.com/api/admin/v1/getListing?token=www")
.then(function (result) {
$scope.feed = result;
console.log(result);
$ionicLoading.hide();
$scope.$broadcast('scroll.refreshComplete');
}, function (reason) {
$ionicLoading.hide();
$scope.$broadcast('scroll.refreshComplete');
});
};
$scope.doRefresh();
$scope.bookmarkPost = function(post){
$ionicLoading.show({ template: 'Post Saved!', noBackdrop: true, duration: 1000 });
BookMarkService.bookmarkFeedPost(post);
};
})
最佳答案
Controller 中有两个用于获取列表的get
请求。
$http.get('http://www.com/api/admin/v1/getListing?token=www')
和
FeedList.get('http://www.com/api/admin/v1/getListing?token=wwww')
这里第二个请求发送第一个请求的成功响应。这不是必需的。从代码中删除一个请求。
其他事情是:
$scope.feed = result;
这里 result
分配给 $scope.feed
变量,因此您只能访问 DOM
中的 feed
对象,而不是数据
变量。您正在尝试访问 ng-repeat
data
对象
data
是 feed
的对象,因此您可以使用 .
(dot) 属性进行访问。
feed.data
从图像中看不到id
,但如果 id 是数组中的可用对象,则其余代码将正常工作。您只需将 ng-repeat
data
更改为 feed.data
<div class="list category-feeds">
<a ng-repeat="source in feed.data" class="item item-icon-right" ui-sref="app.feed-entries({categoryId: source.id, sourceId: (source.id | slugify)})">
<div class="thumbnail-outer">
<pre-img ratio="_1_1" helper-class="">
<img class="thumbnail" ng-src="{{source.id}}" spinner-on-load>
</pre-img>
</div>
<div>
<span class="title">{{source.id}}</span>
<p class="description">{{source.id}}</p>
</div>
</a>
</div
关于javascript - AngularJS Scope.Feed 循环,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33138877/