typescript - 如何在 google.maps.events.addListener(marker, 'dragend', function() { }) 中使用 storage.set(); 在离子 3
问题描述
google.maps.event.addListener(Marker, 'click', (function(Marker) {
return function() {
this.storage.set('mylocation', this.Marker.getPosition());
}
})(Marker));
polyfills.js:3 未捕获的类型错误:无法读取未定义的属性“集”
当我尝试使用来自谷歌地图标记拖动事件的响应在 Ionic 3 中设置存储时出现此错误。
解决方案
无法读取未定义的属性“集”
这意味着“存储”是未定义的。如果存储未定义,请务必在构造函数中声明并正确导入,如下所示:Ionic Storage Docs
import { Storage } from '@ionic/storage';
export class MyApp {
constructor(private storage: Storage) { }
...
// set a key/value
this.storage.set('name', 'Max');
// Or to get a key/value pair
this.storage.get('age').then((val) => {
console.log('Your age is', val);
});
}
如果错误因为this.Marker.getPosition()
为空而被抛出,您可以尝试 Ahkil J 的解决方案:
google.maps.event.addListener(Marker, 'click', (function(Marker) {
return function() {
this.LastLat = Marker.position.lat();
this.LastLng = Marker.position.lng();
this.storage.set('mylocation', this.LastLat + this.LastLng);
}
})(Marker));
推荐阅读
- python-3.x - 如何使用for循环为熊猫数据框附加整行
- amazon-web-services - AWS ECS 中的 fs.file-max 和 ulimit nofile 是否受 EC2 的 fs.file-max 和 nofile 限制?
- python - 包含所有详细信息的 github 存储库
- python - 在 AWS Lambda 上使用 Flask 的 Sentry 未捕获错误
- kdb - KDB Q 和 jupyterlab 不在桃子上使用奴隶
- python - 在 django 模型中,提供一组默认字段,但也允许用户添加自己的字段
- nginx - Nginx 转发基于来自另一个服务的响应
- openssl - 使用 PHPMailer / SMTP / LimeSurvey 拒绝权限
- sql-server - 如何在两个数字之间生成一系列字母数字?
- angular - 如何在 Angular 7 中为 URL 路由添加前缀('/admin')