I'm trying to understand some best practices in Angular and want to combine the mentioned pattern in a factory to retrieve data from a REST API:
function feedFactory($resource) {
var service = {
feedData: [],
};
getFeedFromApi();
return service;
function getFeedFromApi() {
var feed = $resource('http://footballdb.herokuapp.com/api/v1/event/de.2014_15/teams?callback=JSON_CALLBACK', {}, {
query: {
method: 'JSONP'
}
});
feed.query().$promise.then(function(result) {
service.feedData = result.toJSON();
});
}
}
Unfortunately, I can't set the feedData variable of the service object although I receive a valid promise object with data.