angular - ngFor,将输入与 Aloglia Places 功能链接
问题描述
我正在使用 Angular8 在 ngFor 中设置 Algolia Places 输入。当我使用(change)时,它在我第二次在输入中写入时工作正常。这很好,但不完全是我想要的。
我认为函数和输入之间的链接不是在创建输入(逻辑)时自动建立的。我想要的是成功地将输入与函数链接起来。我应该怎么做?
HTML部分:
<ng-container *ngFor="let place of places; let i = index;">
<input id="{{ 'inputaddress' + i}}" (change)="addressSearchIndex(i)" type="text" class="form-control" />
</ng-container>
Component.ts 部分:
addressSearchIndex(index) {
this.placesAutocompleteAddress = placesAlgolia({
appId: <ID>,
apiKey: <Key>,
container: document.querySelector('#inputaddress'+index),
templates: {
value: function(suggestion) {
return suggestion.name;
}
}
}).configure({
type: 'address'
});
this.placesAutocompleteAddress.on('change', function resultSelected(e) {
this.lat = e.suggestion.latlng["lat"];
this.lng = e.suggestion.latlng["lng"];
});
}
解决方案
尝试 keypress 或 keydown 事件而不是更改
推荐阅读
- spring-batch - Spring Batch - 使用远程分区/远程分块时 CPU 利用率高
- flask - 如何动态创建 SQLAlchemy 引擎并在 Flask 中的请求之间使用它?
- amazon-s3 - yace 在 grafana 中不显示任何数据
- mysql - mysql:如何根据其他列对列进行排序
- perl - 无法在 perl 中的 File/Slurp.pm 第 10 行导出符号
- javascript - 从平面列表中删除对象时,未定义不是对象(评估“this.setState”)
- html - 在鼠标悬停时预览图片下方的图片,但只能在像放大镜一样的小圆圈中
- javascript - 外部 Javascript 库 - 升级
- android - Android 的 requestPermission Java 方法是否已弃用?
- java - 如何将 /n 替换为
- java中的标签