서비스가 종속 된 단순 컨트롤러가 있습니다. 일단 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
에서 :
<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' 언급 됨 – Cherniv
죄송합니다. 내 게시물을 편집하십시오. – Fabrizio