I have a pop-up with 2 buttons, Update and Delete. When the Update button is pressed, I want to make the initial pop-up disappear and a new pop-up appear populated with the same fields but editable with another 2 buttons at the bottom, Confirm and Delete.
I want to configure the code for the Update pop-up in a separate method and call it from the HTML button when the Update button is pressed
How do I call the desired method (myFunction) from the HTML written inside the TypeScript Component at the button component?
private initMap(): void {
this.map = L.map('map', {
center: this.centroid,
zoom: 2.8
});
this.tiles = L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png',
{
minZoom: 2.8,
attribution: '© <a href="http://www.openstreetmap.org/copyright">OpenStreetMap</a>'
});
this.tiles.addTo(this.map);
this.powerPlantService.getAll().subscribe((data: any)=>{
console.log(data);
this.geoJsonFeature = data;
L.geoJSON(data, {onEachFeature: myOnEachFeatureMethod}).addTo(this.map)
})
function myOnEachFeatureMethod(feature:any, layer:L.GeoJSON)
{
layer.bindPopup(
"Power Plant Id: " + feature.properties.xxx +
"<br>Power Plant Name: " + feature.properties.xxxx +
'<div style="text-align:center"> '+
//below in the button i want to call the myFunction method. How do I do that?
'<br><button type="button" class="btn btn-primary" style="margin-right: 5px" data = "' + feature.properties.xxx + '" ' + '>Update</button>' +
'<button type="button" class="btn btn-danger" style="margin-left: 5px" data = "' + feature.properties.xxxx + '" ' + '>Delete</button>' +
'</div>'
);
}
}
myFunction(layer: any) {
console.log("Yeet");
layer.bindPopup("Yeet");
}
This is the pop-up displayed when the map pin is clicked

<button onclick="myFunction()">Update</button>Probably it won't work as this function should be defined in a regular javascript file and then included in your project like this: websparrow.org/angular/…. It's probably not what you want to achieve though. I believe, the template you provide will just be interpreted as regular html and won't be compiled by Angular.bindPopupand not Angular. You provide regular html code, which is correctly interpreted by the browser, but it doesn't have any clue where to find these javascript functions. All your code written within an Angular component is recompiled and isolated by Angular. So you can't access this from regular html.