У меня есть простой контроллер со службой в качестве зависимости. Я пытаюсь заполнить область, как только обещание resource
будет разрешено. Когда я console.log()
область, он правильно показывает мне область с данными, но мой ng-repeat не работает. Также я использую угловое расширение chrome
, и в этой области (posts)
не отображаются данные. Что мне не хватает?
Контроллер:
function TimelineController($scope,TimelineService)
{
$scope.posts = [];
$scope.getPosts = function(wall_type,wall_id) {
TimelineService.getPosts(wall_type,wall_id).$promise.then(function(result){
$scope.posts = result.response;
console.log($scope.posts); // it show correctly the data on console
});
}
}
обслуживание
function TimelineService($resource) {
var resource = $resource('/timeline/:postId',
{postId:"@id"}
);
return {
getPosts: function(entity,id)
{
// /timeline?entity=user&id=3 (example url)
return resource.get({entity:entity,id:id});
}
}
};
Ответ от сервера такой:
{success:true, response:[...]}
Изменить:
Я использую директиву для отображения шаблона в ng-repeat
:
function timeline() {
return {
restrict: 'E',
replace: true,
scope: {
type: '@',
ids: '@',
postime: '&'
},
templateUrl:"/js/templates/timeline/post-tmpl.html"
}
};
Итак, на мой взгляд:
<div class="col-md-8" ng-controller="TimelineController">
<timeline type="user" ids="8" postime="getPosts(wall_type,wall_id)"></timeline>
</div>
И короткая версия моего шаблона:
<ol class="timeline" ng-init="postime({wall_type:type,wall_id:ids})">
<li ng-repeat="post in posts">
{{post.poster.fullname}}
</li>
</ol>
ng-repeat
- person Ivan Chernykh   schedule 28.10.2014