【发布时间】:2016-11-22 22:39:43
【问题描述】:
在 angular2 组件中,在 ngOnInit 中,我想在 openlayers 地图单击时获取元素 id。这是我的代码:
map.on("click", (e)=> {
map.forEachFeatureAtPixel(e.pixel, function (feature, layer) {
let id: number=feature.getId();
this.myService.getFeatureDetail(id)
.suscribe(data => this.myArray = data)
})
});
但是当我点击地图时,我收到一个错误,我无法调用未定义的函数“getFeatureDetail”,我也尝试将 id 保存在全局变量中,但它不能解决我的问题。
【问题讨论】:
标签: javascript angular typescript onclick openlayers-3