【发布时间】:2016-07-23 00:51:59
【问题描述】:
我正在尝试创建一个函数来获取位置值以将其传递给使用共享服务的所有组件下面是我的ngOnInit 函数
this.input = document.getElementById('google_places_ac');
var autocomplete = new google.maps.places.Autocomplete(this.input, { types: ['(cities)']});
google.maps.event.addListener(autocomplete, 'place_changed', function () {
var place=autocomplete.getPlace();
this.setValue(place.address_components[3].long_name, place.address_components[2].long_name, place.address_components[1].long_name);
});
问题在于它无法识别 this.setvalue 函数,该函数与我的共享服务或与 this.variable 共享值的任何变量,它的 javascript“this”问题。而且我什至无法让这个函数与我的构造函数一起使用,它在 getElmentById 处引发错误。
有箭头功能的解决方案,但我不知道如何在这种情况下使用它,所以请帮助我..
【问题讨论】:
标签: javascript api google-maps-api-3 typescript angular