模板:
<div *ngFor="let location of Item.Locations; let i = index;">
<input #searchBox type="text" >
</div>
代码:
@ViewChild('searchBox') geocodeTest : ElementRef;
searchGoogleLocation(){
let input: any = this.geocodeTest.nativeElement;
console.log(this.geocodeTest);
let searchBox = new google.maps.places.Autocomplete(input);
console.log(searchBox);
searchBox.addListener("place_changed", () => {
this._ngZone.run(() => {
console.log('listening');
let place = searchBox.getPlace();
if (place) {
let loc = {
name : place.formatted_address,
latLng : place.geometry.location.toJSON
}
return ;
}
})
});
}