This will not work, your code is fine but it's by design of Angular.
Whenever you pass some content via innerHTML
, Angular is just going to render that content does not evaluate any expression
or binding
within that content like you did by adding a click event.
So In order to achieve this (as per your requirement), you can wrap your content into another component and pass data via @input
property binding and display it into the browser.
For more detail you can read out here -
- Angular 2 innerHTML (click) binding