Any suggestions on how I’d get recursion to work on initialize?
I’m trying to call a function with initialize() that will check to see if an outside library (Google Maps API) is loaded yet, and if it is, call a function related to it, and if it’s not, wait 500ms, then call itself again to see if the library is loaded yet.
So far, no luck. Am I missing something?
initialize() {
this.whenGoogleLoadedDo()
}
whenGoogleLoadedDo() {
if (typeof google != 'undefined')
this.initAutocomplete();
else
setTimeout(function () {
console.log('setTimeout Called')
this.whenGoogleLoadedDo()
}, 500)
}
initAutocomplete() {
autocomplete = new google.maps.places.Autocomplete(
/** @type {!HTMLInputElement} */
// (document.getElementById('autocomplete')), {});
this.autocompleteTarget, {});
// When the user selects an address from the dropdown, populate the address
// fields in the form.
autocomplete.addListener('place_changed', () => {
this.clearGeoFields()
this.fillInAddress()
});
}