I have a component which gets some content after the page has been loaded. The content sometimes contains hyperlinks, which I change to replace the href
attribute with the Angular [routerLink]
.
The problem that I am having is that when this is displayed on the page, it doesn't get compiled by Angular and therefore is just useless html.
I have taken a look at [innerHtml]
which works with plain html but it doesn't seem to compile the [routerLink]
. The following is what I tried to test it:
TS:
public addHtml() {
this.html = "<a [routerLink]=\"['Route']\">Route</a>";
}
HTML:
<button (click)="addHtml()">Add html</button>
<div [innerHtml]="html"></div>
Output HTML:
<div _ngcontent-oli-5=""><a [routerlink]="['Route']">Route</a></div>
The anchor tag doesn't get rendered as a hyperlink.
It would be great if someone could point me into the right direction. Thanks