angular.module('sample').factory('PostService', ['$resource', '$rootScope', '$q',
function ($resource, $rootScope, $q) {
var PostService = $resource('/api/:action/:hub_id/posts', {}, {
posts: {
method: 'GET',
params: { action: 'feed', hub_id: '90f9a03', isArray: false }
};
return PostService;
}]);
$scope.getPosts = PostService.posts(function(posts) {
$scope.posts = posts.results;
console.log($scope.posts); //work
});
console.log($scope.posts); //undefined