I have a project in Angular 2 with Leaflet, I would like to call the simple function by clicking the button, but I get
ReferenceError: <function> is not defined at HTMLButtonElement.onclick
Here is my code. Everything works, but the function not.
export class MapComponent implements OnInit {
//layer
googleStreets = L.tileLayer('http://{s}.google.com/vt/lyrs=m&x={x}&y={y}&z={z}',{
maxZoom: 30,
subdomains:['mt0','mt1','mt2','mt3']
});
//!!!The FUNCTION
test() {
console.log('test');
}
constructor () {}
ngOnInit() {
this.ParseService.getJ().subscribe(data => {
this.myData = JSON.parse(data);
//set markers and popUps
for(let i = 0; i < this.myData.length; i++) {
let lat =+((this.myData[i])['lat']);
let lng =+((this.myData[i])['lng']);
this.id = (this.myData[i])['code'];
//HERE IS THE PROBLEM. BUTTON APPEARS BUT FUNCTION IS NOT AVAILABLE
let popUp = (this.myData[i])['displayName'] +
'<br/><button onclick="test">Raumplan</button>';
let markerLocation = L.latLng(lat, lng);
let marker = new L.Marker(markerLocation, {icon: customIcon});
map.addLayer(marker);
marker.bindPopup(popUp);
}
});
Could you please help me with workaround?