I am creating an application in angular 2. I want to add a click event to a dynamically added html element. I am defining a string (contentString), and in this string I am defining an html element.
var contentString = '<b>' + this.mName + '</b><br/> ' + this.mObject.category + '<br/> Click here for more information <button (click)="navigate()">Navigate here</button>';
This line is placed inside the html element as follows:
var boxText = document.createElement("div"); boxText.innerHTML = contentString;
Although when checking an element it has a certain click event, but it does not fire.
![[image 1]](https://fooobar.com//img/c6ac6ad2b576cc16660118fcd55c889c.jpg)
![[image 2]](https://fooobar.com//img/25d3e767a6229e09dd53f245bc371087.jpg)
when clicked, a console log follows
navigate() { console.log("eeeehnnananaa"); }
But that does not work. Any solution?
source share