so I'm working on a project where I have a dataset and I have to retrieve various statistics on said dataset depending on user input by retrieving data from a server.
I'm trying to set up a AngularJS service which has various methods that return various information on a given data point.
Here is a public method from the service:
function test() {
return $http.get('blahblah.api.../datapoint1')
.success(function(data) {
console.log(data.name);
return data.name;
});
}
Here is the relevant part from the controller:
self.data = service.test();
console.log(self.data);
Interesting enough, the console.log(data.name) within the success of the http call gives me exactly what I want. The name of the given data point. However the console.log(self.data) outside of its scope gives me the original promise object. Any method I use to send information outside of the scope of "success" gives me a promise object. Why is this? And is there any way of getting around this? It seems awfully inefficient to have to deal with the error handling in the controller.