I'm stuck at accessing variables through an event's object. Is there something I can refactor in this code, because I need to display some annotations in my templateUrl after I set them in an event click of the map. Here is the code:
import { Component, OnInit, AfterViewInit } from '@angular/core';
declare var ol: any;
@Component({
selector: 'my-map-app',
templateUrl: 'app.component.html'
})
export class AppComponent implements OnInit, AfterViewInit {
static draw: any;
annotations: any[];
constructor() {
this.annotations = [];
}
ngOnInit(): void {
// ADD MAP
AppComponent.map = new ol.Map({
target: 'map',
layers: layers,
view: new ol.View({
center: ol.proj.fromLonLat([10, 10]),
zoom: 2
})
});
// Action when clicking on a Point (no edition mode)
AppComponent.map.on('singleclick', function(evt) {
// here I want to access and set the array of annotations
//this.annotations or AppComponent.annotations is not available
});
}
Edit: on app.component.html:
<select >
<option *ngFor="let annotation of annotations">{{annotation.name}}</option>
</select>