Question has been updated with a solution. I have successfully retrieved a JSON feed from .
Although the JSON data is appearing in my scope and displaying in my pre tags, it's not populating in my ng-repeat as expected.
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>
Update After incorporating suggestions from various sources, here is the revised code: Controller
$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;
}
if (response.data && response.data.feed && response.data.feed.approved_images && response.data.feed.approved_images.length ) {
$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>