[英]Error when calling my function functionX : ERROR TypeError: Cannot read property 'functionX' of null
我正在使用Ionic3,正在尝试在我的about.ts文件中集成地理位置科尔多瓦源代码,但出现一个奇怪的错误:
当我从html调用getMapLocation()时:
(click)="getMapLocation()"
结果如下:
core.js:1448 ERROR TypeError: Cannot read property 'functionX' of null
at webpackJsonp.195.AboutPage.onMapSuccess (about.ts:94)
at t.invoke (polyfills.js:3)
at Object.onInvoke (core.js:4749)
at t.invoke (polyfills.js:3)
at r.runGuarded (polyfills.js:3)
at polyfills.js:3
为什么我不能称呼“ functionX”?
//Imports + Decorators
export class AboutPage{
//Constructor + some code
getMapLocation() {
navigator.geolocation.getCurrentPosition(this.onMapSuccess, this.onMapError, { enableHighAccuracy: true });
}
onMapSuccess(position) {
this.functionX();
console.log(position);
let Latitude = position.coords.latitude;
console.log('sss');
let Longitude = position.coords.longitude;
console.log('11');
this.getMap(Latitude, Longitude);
console.log('22');
}
functionX(){
console.log('functionX');
}
上下文不正确,请将函数绑定或传递给前两个getCurrentPosition
参数:
navigator.geolocation.getCurrentPosition(this.onMapSuccess.bind(this), this.onMapError.bind(this), { enableHighAccuracy: true });
要么
navigator.geolocation.getCurrentPosition(() => this.onMapSuccess(), () => this.onMapError(), { enableHighAccuracy: true });
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.