Presenting my innovative service:
app.service('trackService', ['$http', function($http) {
var information;
this.fetchData = function(limit) {
$http({
method: 'GET',
url: 'http://ws.audioscrobbler.com/2.0/?method=chart.gettoptracks',
params: {api_key: 'e8452c5962aafbb3e87c66e4aaaf5cbf', format: 'json', limit: limit}
}).success(function(result) {
this.information = result.tracks; console.log(this.information); return this.information;
});
}
}]);
and accompanying controller -
app.controller('artistSongsCtrl', ['$scope', 'trackService', function($scope, trackService) {
$scope.data = trackService.fetchData(10);
//console.log($scope.data);
}]);
What is the best approach to transfer data to the controller using a $http service within a custom service?