javascript - Ionic 4 Google 使用 ReactiveForm 自动完成
问题描述
我想在我的项目中使用 googlemap places API 进行自动完成,但它给了我一个错误:
TypeError: Cannot read property 'getInputElement' of undefined
.html
<section
[formGroupName]="i"
*ngFor="let tech of form.controls.technologies.controls; let i = index">
<ion-item-group>
<ion-item-divider color="light">Station #{{ i + 1 }}</ion-item-divider>
<ion-item>
<ion-label position="floating">Technology name:</ion-label>
<ion-input
#autoCompleteStation
type="text"
maxlength="50"
formControlName="name"></ion-input>
</ion-item>
</ion-item-group>
</section>
.ts
@ViewChild('autoCompleteStation', {static: true}) autoCompleteStation: any;
ngAfterViewInit(): void {
this.autoCompleteStation.getInputElement().then((input:HTMLInputElement)=>{
var autocomplete2 = new google.maps.places.Autocomplete(input, {
//somee code
});
}
});
PS:当我删除 for 循环时它可以工作,但是当我再次添加它时,它会给出上面的错误。请问有什么建议吗?
解决方案
推荐阅读
- c - 为什么 '?' 和 '\?' 在 C 中给出相同的输出?
- python - 我有一个对应于 2018 年第 1 周的 ISO 8601 周数(例如:201801)。pyth 中的最佳方法是什么
- vba - 如何在 Outlook 中添加消息框以发送按钮?
- javascript - React Apollo - 如何在单个 pollInterval 中进行多个查询
- bash - 如何在每次提交时运行脚本
- pandas - 如何切片以日期为索引的熊猫数据框
- sql-server - SQL Server - COUNT 函数 - 可能与 GROUP BY 冲突?
- javascript - 如何知道 HTMLMediaElement 何时完成
- android - 保存 ViewPager 中嵌套片段的状态
- java - SQLException:Play Framework 中 Ebean 和 rawSql 的列索引超出范围