【发布时间】:2016-10-24 03:28:06
【问题描述】:
我正在尝试使用Weakmap() 在控制器中调用服务,但它给出的错误为Cannot read property 'getWeather' of undefined。以下是我的代码:
const SERVICE = new WeakMap();
export default class WeatherController {
constructor(apiService) {
SERVICE.set(this, apiService);
if (navigator.geolocation) {
navigator.geolocation.watchPosition(this.geoSuccess, this.geoFailed);
}
}
geoSuccess(position) {
// This gives an error mentioned above
SERVICE.get(this).getWeather(position.coords.latitude, position.coords.longitude);
}
geoFailed(err) {
console.log('Error:', err);
}
}
WeatherController.$inject = ['apiService'];
【问题讨论】:
标签: javascript angularjs ecmascript-6