My app has a service that is supposed to return an array of objects (tweets from the twitter api) that looks like:
.service('twitterService', function($http) {
this.getTweets = function(){
$http.get('http://example.com/?json=get_twitter_sidebar').success(
function(data, status, headers, config) {
if (data.status == 'ok') {
return data.feed;
} else {
return 'Error Retrieving Feed'
}
});
}
})
This service seems to work; it calls the api and returns the desired object array (I used console.log to verify). However, I can't seem to pass the returned array to my controller:
var TopPageCtrl = function($scope, $window, $http, twitterService) {
$scope.feed = twitterService.getTweets();
};
When I use console.log($scope.feed), it returns undefined. I've tried a million approaches but nothing seems to work. What am I doing wrong?