更新的问题和解决方案的提供。 我从https://filters.rocks/embed/466.json得到一个JSON饲料。NG重复
的JSON是未来通过我的范围,但我可以在我的前标签,但不管是什么原因,它只是不填充我的NG-重复观看。
app.controller('InstagramCtrl', ['$scope', '$http',
function($scope, $http) {
$scope.items = [];
$http.get('https://filters.rocks/embed/466.json').then(function(response) {
$scope.items = response;
instagramSuccess($scope, $scope.items);
});
var instagramSuccess = function(scope, response) {
if (response.data.length <= 0) {
$scope.error = response.meta.error_type + ' | ' + response.meta.error_message;
return;
}
if (response.data.length > 0) {
$scope.items = response.data;
} else {
$scope.error = "This hashtag has returned no results";
}
};
}
]);
HTML
<div class="container" ng-controller="InstagramCtrl">
<div class="row">
<div class="col-md-12">
<div class="panel panel-default">
<div class="panel-heading">
</div>
<div class="panel-body">
<ul class="instagram-list" ng-repeat="item in items">
<li>
<small>{{item.data.feed.id}}</small>
<img ng-src="{{item.data.feed.approved_images.medium}}" width="250">
</li>
</ul>
</div>
<pre> filter.rocks {{ items | json }} </pre>
</div>
</div>
</div>
更新 我把点点滴滴,从每个人,结束了这一点; 控制器
$scope.items = [];
$http.get('https://filters.rocks/embed/466.json').then(function(response) {
instagramSuccess(response);
});
var instagramSuccess = function(response) {
if (!response.data) {
$scope.error = response.meta.error_type + ' | ' + response.meta.error_message;
return;
}
// check if data is defined if so, check objects are defined, then if array is defined.
if (response.data && response.data.feed && response.data.feed.approved_images && response.data.feed.approved_images.length) {
//if all good $scope.items becomes array
$scope.items = response.data.feed.approved_images;
} else {
$scope.error = "This hashtag has returned no results";
}
};
HTML
<ul class="instagram-list" ng-repeat="item in items">
<li class="instagram-item">
<small style="color:blue;">{{item.id}}</small>
<div bg-img="{{item.medium}}" width="250"></div>
</li>
</ul>
打印{{items}}并查看您是否正在调用正确的子属性。这是一个常见的错误,你会收到一个地图,但你继续迭代它作为一个列表。 – madhairsilence