【发布时间】:2016-07-23 02:22:36
【问题描述】:
这是我的ngOnInit 函数
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 = autocomplete.getPlace();
instance.setValue(place.address_components[3].long_name, place.address_components[2].long_name, place.address_components[1].long_name);
});
这是我的setValue() 函数
public setValue(a,b,c) {
this.coutnry = a;
this.state = b;
this.city = c;
this.sharedService.country = this.coutnry;
this.sharedService.city = this.city;
this.sharedService.state = this.state;
console.log(a, b, c);
}
下面是我的 html 模板,用于显示和获取值
<input id="google_places_ac" attr.state="{{state}}" attr.country="{{coutnry}}" name="google_places_ac" type="text" value="{{city}}" class="form-control" />
问题是我的 html 属性在调用 place_changed 函数后没有得到更新,我需要做些什么来获得更新的值吗?
【问题讨论】:
标签: typescript angular