I want to add click events to images present in inner html. But when I try to add it, it won't work.
Template
<div [innerHTML]="myHtml"></div>
Code
myHtml;
ngOnInit() {
const root = document.createElement('div');
root.innerHTML = this.getHtml();
const images = root.getElementsByTagName('img');
Array.prototype.forEach.call(images, (image: HTMLImageElement, i) => {
image.addEventListener('click', (event: any) => {
console.log('click', event);
});
});
this.myHtml = root.innerHTML;
}
Here is the stackblitz