When working with an Angular2 component, I am trying to retrieve the element id on a click event on an OpenLayers map within the ngOnInit function. Below is the code I am using:
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)
})
});
Unfortunately, I am encountering an error when clicking on the map that states I cannot call the function 'getFeatureDetail' of undefined. I have also attempted to save the id in a global variable, but this does not resolve the issue.