javascript - ng-repeat displaying only the last item -
i know mistake.
i receiving json object contains wordpress posts, when try render posts in dom, post 12 times in list, last item
<div ng-repeat="post in posts"> <h2 ng-bind-html="post.title"></h2> <p>{{:: post.date | date}}</p> </div>
controller
$scope.posts = []; $scope.dorefresh = function() { $scope.posts = freshlypressed.getblogs($scope); $scope.$broadcast('scroll.refreshcomplete'); } $scope.dorefresh();
the service
.service('freshlypressed', function($http, $q) { return { getblogs: function($scope) { var posts = []; $http.get('http://urbanetradio.com/wp-json/posts') .success(function(result) { _.each(result, function(posts) { console.log(posts.title); $scope.posts = posts; }); }) } });
_.each(result, function(posts) { console.log(posts.title); $scope.posts = posts; });
this mistake is. lodash loops through posts , and assigns $scope.posts 1 post each time, thats why last one.
try:
$http.get('http://urbanetradio.com/wp-json/posts') .success(function(result) { $scope.posts = result; }) }
Comments
Post a Comment