Typescript Logic Issue With Angular 2 And Google Maps Api
i am trying to create a function to get the location value to pass it to all the components using shared service below is my ngOnInit function this.input = document.getElementB
Solution 1:
Inside the place_changed
-callback the keyword this
points to the Autocomplete-instance.
You'll need to create a closure:
var instance = this,
autocomplete;
instance.input = document.getElementById('google_places_ac');
autocomplete = new google.maps.places.Autocomplete(instance.input, {
types: ['(cities)']});
google.maps.event.addListener(autocomplete, 'place_changed', function () {
var place=this.getPlace();
instance.setValue(place.address_components[3].long_name,
place.address_components[2].long_name,
place.address_components[1].long_name);
});
Post a Comment for "Typescript Logic Issue With Angular 2 And Google Maps Api"