I rely on a component i.e. Angular Material Autocomplete that requires a function that returns a value.
Unfortunately, I am not sure how to return something in due time from the nested asynchronous function below (addressAutocomplete()
):
$scope.chooseAddress = function (input) {
var results = [];
if (input) {
geolocationService.addressAutocomplete(input, function (data) {
results = data.predictions;//Will be fired asynchronously and too late...
});
}
return results;//I have to return something from my function...
};
By the time the addressAutocomplete function has completed, the results
var has already been returned and it is of course an empty array...
Can someone please help?