Я пытаюсь добавить объекты google maps автоматически в ionic 2 project, чтобы обновить местоположение пользователя. Однако addEventListener не работает, и нет ошибок в консоли. кто-нибудь скажет мне, где я ошибаюсь?google maps places autocomplete addEventListener не работает
ngAfterViewInit() {
let input = <HTMLInputElement> document.getElementById("auto");
console.log('input', input);
let options = {
componentRestrictions: {
country: 'IN',
types: ['(regions)']
}
}
let autoComplete = new google.maps.places.Autocomplete(input, options);
console.log('auto', autoComplete);
google.maps.event.addListener(autoComplete, 'place_changed', function() {
this.location.loc = autoComplete.getPlace();
console.log('place_changed', this.location.loc);
});
}
<ion-label stacked>Search Location</ion-label>
<input type="text" id="auto" placeholder="Enter Search Location" [(ngModel)]="location.loc" />
index.html
<script src="https://maps.googleapis.com/maps/api/js?key=xxxxxxxxxxxxxx&libraries=places"></script>
Я пробовал, но все равно, пока я не печатаю ни одного всплывающего меню, но когда я нажмите enter.log ('place_changed', this.location.loc) печатает введенное значение – Idlliofrio
Вы меняли 'function() {' to '() =>'? – yurzui
yes Я изменил его на функцию стрелки – Idlliofrio