0
我正在使用angularjs get方法从服务器获取提要数组。这是我的控制器代码。Angularjs调用同步
$scope.feeds = new Array();
$scope.feeds = FeedService.getFeeds();
console.debug("in controller : "+$scope.feeds);
和我FeedService代码firbug控制台我为$scope.feeds
越来越undefined
而在FeedbackService
它打印JSON对象是
getFeeds : function(){
$http.get('/app/get').success(function(response){
console.debug(response);
return response;
}).error(function(){
console.debug("failed");
});
}
。我知道我得到undefined
,因为代码是同步的。我能做些什么来处理这个问题。我的html是
<div ng-repeat = "feed in feeds">
<feed feed-text={{feed.feedText}} feed-user={{feed.user}}></feed>
</div>
我没有打印任何东西在页面上。
三江源这么多,它的工作 – Shahzeb
不客气。我建议http://egghead.io作为关于angular的主题的视频教程的一个很好的资源。他解释了承诺的概念,比我所能做的更好:) – Sprottenwels
谢谢,我会看看这些教程。 – Shahzeb