I'm trying to return something from an angular function to the html but from the success function of the http request. In this case, I'm using Google API to get the miles, then I want to return it to html but it won't return unless it's in the main function.
This is the code in the controller :
$scope.getDistance=function(pcodefrom,pcodeto,id){
if($scope.milesGot.indexOf(id) == -1) { //if not already done this request once
$scope.milesGot.push(id);
var url = 'mylinktogooglematrixapiishere';
$http({method: 'GET', url: url}).success(function(data) {
var to = data.destination_addresses;
var from = data.destination_addresses;
var miles = data.rows[0].elements[0].distance.text;
return miles;
}).error(function(data){
});
}
}
The 'miles' variable is fine, even when I change it to plain text like "test" it won't return.