Explanation of code
I have a function which extracts the value from an html input and returns a formatted address. I call this function twice storing each address into appropriate variable. Once I have converted both inputs I want to call another function, function z.
ngAfterViewInit() {
//get input elements, get the first tag within the ion-input tag
this.searches.startSearch = document.getElementById("startSearch").getElementsByTagName('input')[0];
this.searches.endSearch = document.getElementById("endSearch").getElementsByTagName('input')[0];
var address1 = this.placeDecode(this.searches.startSearch)
var address2 = this.placeDecode(this.searches.endSearch)
this.methodZ(address1,address2);
}
//method convertes input into formatted address
private placeDecode(input : HTMLInputElement) {
var location = input.value;
var geoCode = new google.maps.Geocoder();
geoCode.geocode({
address: location
}, function (result, status) {
if (status === 'OK') {
return result[0].formatted_address;
} else {
return null;
}
});
}
Problem
The problem I am having is I only want to call function Z once both input have been converted. I have tried using callback but i can't call a function z within a callback.