Ionic framework 修复类型为';HTMLElement';不可分配给类型为';HTMLInputElement';
我正在尝试在新的爱奥尼亚应用程序中设置谷歌地图放置自动完成 问题就在这里。在第一次搜索时,我在控制台中发现以下错误:Ionic framework 修复类型为';HTMLElement';不可分配给类型为';HTMLInputElement';,ionic-framework,google-maps-autocomplete,Ionic Framework,Google Maps Autocomplete,我正在尝试在新的爱奥尼亚应用程序中设置谷歌地图放置自动完成 问题就在这里。在第一次搜索时,我在控制台中发现以下错误: TypeError: Cannot read property 'place_id' of undefined 终端中的此错误: TS2345: Argument of type 'HTMLElement' is not assignable to parameter of type 'HTMLInputElement' 但是,在第二次搜索中,我得到了place_id,没有任
TypeError: Cannot read property 'place_id' of undefined
终端中的此错误:
TS2345: Argument of type 'HTMLElement' is not assignable to parameter of type 'HTMLInputElement'
但是,在第二次搜索中,我得到了place_id,没有任何错误
这是我的(简化的).ts文件
import { Component, OnInit } from '@angular/core';
import { google } from "google-maps";
import { Platform } from '@ionic/angular';
@Component({...})
export class AddaddressPage implements OnInit {
autocomplete:any;
constructor(public platform: Platform) {}
ngOnInit() {
this.platform.ready().then(() => {
this.autocomplete = new google.maps.places.Autocomplete(document.getElementById('autocomplete'));
this.autocomplete.setFields(['place_id']);
});
}
fillInAddress() {
var place = this.autocomplete.getPlace();
console.log(place);
console.log(place.place_id);
}
}
以及我使用的输入:
<input id="autocomplete" type="text" (change)="fillInAddress()" />
我该怎么做呢?玩过之后,这里是诀窍!需要ViewChild和Ion输入 .html
<ion-input #autocomplete type="text"></ion-input>
在玩过之后,这里是诀窍!需要ViewChild和Ion输入 .html
<ion-input #autocomplete type="text"></ion-input>