I wonder if it is possible to bind a function to a html Template via the template-string notation.
So if i do this
let dynTamp = `<div> ${device.name} </div>`;
it works perfectly well, but this
let dynTamp = `<button (click)="${someFunction}"></button>`;
does not bind the function to the click event. Am I missing something here?
The Background: I am working with LeafletJs and dynamically create markers on a map, whose popovers should contain buttons:
this.devices.forEach(device => {
L.marker([Number(device.map_x), Number(device.map_y)], {icon: this.icon})
.bindPopup(`<h2> ${device.name}</h2>
<button (click)="${doThis}"></button>
<button (click)="${doThat}"></button>`)
.addTo(this.map)
}
(click)="someFunction()". And Angular templates need to be compiled. You can't just dynamically generate HTML containing Angular markup and hope it works. It won't.