4

Given the following innerHtml statement in a template:

<div [innerHtml]="content"></div>

and the following code in the component:

this.content = '<a href (click)="clickMe()">Click Me</a>;'

clickMe(){
    alert('link was clicked');
}

Clicking on the link does nothing, as the anchor is not compiled. How to make Angular aware of the (click) event? In AngularJS I used $compile but I couldn't find an equivalent in Angular 6.

ps0604
  • 1,227
  • 23
  • 133
  • 330
  • 5
    Possible duplicate of [Angular 2 innerHTML (click) binding](https://stackoverflow.com/questions/37676726/angular-2-innerhtml-click-binding) – ConnorsFan Oct 07 '18 at 00:30

0 Answers0