I\'m building an app in angular 2. I want to add a click event to a dynamically added html element. I define a string (contentString), and in this string I define the html e
In my case I do these--
var boxText = document.createElement("div");
const contentString = '' + this.mName + '
' + this.mObject.category +
'
Click here for more information ';//as per your code
boxText.innerHTML = contentString;
const button = document.createElement('button');
button.addEventListener('click', (e) => {
this.navigate();//your typescript function
});
button.innerText = 'Navigate here';
boxText.appendChild(button);