我第二次进入页面时只收到上述错误,所以我确定这是我在代码中犯的错误:
@ViewChild('search') public searchElement: ElementRef;
@ViewChild('searchPlaces') public searchPlacesElement: ElementRef;
@ViewChild('myInput') public myInput: ElementRef
ngOnInit(){
this.mapsApiLoader.load().then(
() => {
let autocomplete = new google.maps.places.Autocomplete(this.searchElement.nativeElement, {types:['(cities)']});
autocomplete.addListener("place_changed", () => {
this.ngZone.run(() => {
let place: google.maps.places.PlaceResult = autocomplete.getPlace();
if(place.geometry === undefined || place.geometry === null){
return;
}
this.location = place.formatted_address;
});
});
}
)
this.mapsApiLoader.load().then(
() => {
let autocomplete = new google.maps.places.Autocomplete(this.searchPlacesElement.nativeElement, {types:['(cities)']});
autocomplete.addListener("place_changed", () => {
this.ngZone.run(() => {
let place: google.maps.places.PlaceResult = autocomplete.getPlace();
if(place.geometry === undefined || place.geometry === null){
return;
}
this.intPlaces.push(place.formatted_address);
});
});
}
)
}
<p>
<input [(ngModel)]="location" placeholder="Enter city"
#search>
</p>
非常感谢任何帮助。
当我最初进入页面时,我没有收到错误并且自动填充功能正常...如果我开始输入城市名称,则自动填充其余部分。第二次进入页面时,我在标题中收到错误。